Oracle JDBC unicode parameter corrupted (DB insert proc)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dzenanz
    New Member
    • Feb 2008
    • 45

    #1

    Oracle JDBC unicode parameter corrupted (DB insert proc)

    Calling a stored procedure from Java with ojdbc 1.4 corrupts (converts to ¿) unicode characters that are not contained in DB's current charset.
    Calling this proc from C# works as expected (all unicode characters are properly stored).
    Code:
    String driver = "oracle.jdbc.OracleDriver";
    Class.forName(driver);
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = DriverManager.getConnection(url, username, password);
    CallableStatement storedProc = conn.prepareCall("{call SMSC.p_smsu_campaign_insert(?,?,?,?,?,?)}");
    
    String campaign="_šđčćž ò#±¦ţ!ę";
    storedProc.setString("Campaign_name", campaign); //<----problem here!
    //Campaign_name parameter in DB is nchar type (oracle's unicode type)
    /*set other parameters*/
    storedProc.execute();
    Do you have any idea what is the cause?
    Note: this is a simplification of my previous post
  • dzenanz
    New Member
    • Feb 2008
    • 45

    #2
    If anyone comes by the same problem again, here is the solution:
    Code:
    storedProc.setString("Campaign_name", campaign);
    ((OraclePreparedStatement) storedProc).setFormOfUse(1, OraclePreparedStatement.FORM_NCHAR); //<---this makes the difference!

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by dzenanz
      If anyone comes by the same problem again, here is the solution:
      Code:
      storedProc.setString("Campaign_name", campaign);
      ((OraclePreparedStatement) storedProc).setFormOfUse(1, OraclePreparedStatement.FORM_NCHAR); //<---this makes the difference!
      Not that I know another solution to your problem but I find the solution you
      showed here very ugly: it ties your code to the Oracle database forever. Better
      isolate that trickery-dickery to a small utility class that can be changed when
      you have to migrate to another database.

      kind regards,

      Jos

      Comment

      Working...