Oracle Utf8- Setstring Method Doesn't Work With Nvarchar2

  • Thread starter Thread starter Ivan Chan
  • Start date Start date
Status
Not open for further replies.
I

Ivan Chan

Guest
setString(int parameterIndex, String s) in PreparedStatement doesn't seem to support UTF8 characters out of the box for NVARCHAR, NVARCHAR2 and NCHAR column when using Progress Oracle JDBC driver 5.1.4. However, this issue is not reproducible using default native driver. Currently, we found a way to work around this issue in progress oracle jdbc driver by creating a wrapper and overriding setString() method for PreparedStatement. Redirecting setString() method to setObject(). public void setString(int parameterIndex, String x) throws SQLException { try { type = preparedStatement.getParameterMetaData().getParameterTypeName(parameterIndex); } catch (Exception ex) {}; if (type == null) preparedStatement.setString(parameterIndex, x); else if (type.startsWith("nvarchar")) preparedStatement.setObject(parameterIndex, String.valueOf(x), ExtTypes.NVARCHAR); else if (type.startsWith("nchar")) preparedStatement.setObject(parameterIndex, String.valueOf(x), ExtTypes.NCHAR); else preparedStatement.setString(parameterIndex, x); return; } However, it is hard to maintain a wrapper for this workaround for us. It will be easier to have a URL connection parameter to apply this workaround in your driver side. Specially, we use hibernate a lot directly to get JAVA object back from database.

Continue reading...
 
Status
Not open for further replies.
Back
Top