开发者

Problem while storing accented characters to the database using spring framework

开发者 https://www.devze.com 2023-03-07 10:17 出处:网络
I am using a stored procedure to insert some data to the SQL 2005 DB using Spring Framework\'s stored procedure class. The class declaration is somewhat like:

I am using a stored procedure to insert some data to the SQL 2005 DB using Spring Framework's stored procedure class. The class declaration is somewhat like:

       private class InsertShippingAddress extends StoredProcedure {
    public InsertShippingAddress(final DataSource ds) {
      super(ds, "usp_adiPromoInsertShippingDetail");
      super.declareParameter(new SqlPara开发者_JAVA百科meter("in_FirstName", Types.VARCHAR));

      compile();
    }
  }

I'm executing the SP like:

     final InsertShippingAddress insertShippingAddress = new InsertShippingAddress(
            getJdbcTemplate().getDataSource());
    final Map<String, Object> inParams = new HashMap<String, Object>();
    inParams.put("in_FirstName", name);
   insertShippingAddress.execute(inParams);

now the problem is, the name string containg accented characters in french language, but while the storage the string èüÀÔàé is getting stored as eu¨AO^a`e´ in a distorted manner. But if I actually go and execute the SP through SQL management studio, it saves correctly. I don't know where am I going wrong. Please help.

Thanks in advance, Narain


Disclaimer: I am not a java programmer

The problem may be in this line

  super.declareParameter(new SqlParameter("in_FirstName", Types.VARCHAR));

since you're using a the VARCHAR type, non-ASCII characters may not be correctly converted.

Perhaps you should be using the following?

  super.declareParameter(new SqlParameter("in_FirstName", Types.NVARCHAR));

EDIT

If you can't use the NVARCHAR type, one work-around might be to cast the string to hex then pass it to the database as Types.VARBINARY (or something similar) - the database should handle type conversion correctly. I have no idea if Spring will let you do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消