![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
I need to store all possible 256 characters in the DB using JDBC. All works well when I use VARCHAR2 (I needed to set -Dfile.encoding=ISO-8859-1 parameter on the JVM). I can store values using resultSet.setString() and retrieve using resultSet.getString(). The problem is that I need to store values longer than 4000 bytes. I converted the column type to Clob and things broke: I set the value using preparedStatement.setString() and it is stored correctly in the database (I verified it using Toad). But when I use this code to get the values, characters in the range 0x80-0xa0 come back as 253 instead: Clob clob = resultSet.getClob(1); String val = clob.getSubString(1, len); I've tried all methods on Clob and CLOB but everything I tried screwes up these characters. Please help!! Thanks. |
#2
| |||
| |||
|
|
"Ilia" <nospam (AT) deathtospam (DOT) com> wrote I need to store all possible 256 characters in the DB using JDBC. All works well when I use VARCHAR2 (I needed to set -Dfile.encoding=ISO-8859-1 parameter on the JVM). I can store values using resultSet.setString() and retrieve using resultSet.getString(). The problem is that I need to store values longer than 4000 bytes. I converted the column type to Clob and things broke: I set the value using preparedStatement.setString() and it is stored correctly in the database (I verified it using Toad). But when I use this code to get the values, characters in the range 0x80-0xa0 come back as 253 instead: Clob clob = resultSet.getClob(1); String val = clob.getSubString(1, len); I've tried all methods on Clob and CLOB but everything I tried screwes up these characters. Please help!! Thanks. what platform is your client on (the machine that runs the java and prints out your String val). are you sure this has to do with oracle, since you say that it gets inserted correctly one way or the other? in the following java snippet: char c = 0x80; System.out.println(c); on windows, this code will print a ? when executed. since unicode from 128-255 uses ISO-8859-1, and 128-159 are control characters in ISO-8859-1, they will look busted in Cp1252 (windows default), which don't have those control characters. what characters are you expecting to see? ps, are you sure it's 0x80-0xa0, and not 0x80-9f (i.e., 128-159)? |
#3
| |||
| |||
|
|
Thank you for your interest, here is more info: I run java program on Windows XP professional, JVM 1.3.1 with a -Dfile.encoding=ISO-8859-1 JVM parameter. Oracle server is running under Linux 7.3. With this parameter, code char c = 0x80 System.out.println(c); prints out a Euro symbol. You are right and the range is 0x80-0x9f. |
#4
| |||
| |||
|
|
woops. i don't know why it doesn't work for you then, it prints out the euro for me fine (and i have almost the exact same setup as you). maybe you should post your code (the CLOB insert as well as the retrieval and print statements) the fact that it's only 0x80-0x9f still makes me think it has something to do with Cp1252 vs. ISO-8859-1. "Ilia" <nospam (AT) deathtospam (DOT) com> wrote Thank you for your interest, here is more info: I run java program on Windows XP professional, JVM 1.3.1 with a -Dfile.encoding=ISO-8859-1 JVM parameter. Oracle server is running under Linux 7.3. With this parameter, code char c = 0x80 System.out.println(c); prints out a Euro symbol. You are right and the range is 0x80-0x9f. |
#5
| |||
| |||
|
|
int num = stmt.executeUpdate("delete from test"); // t.in contains 256 characters 0x00-0xff, -Dfile.encoding=ISO-8859-1 ensures that we use ISO-8859-1 String chars = Misc.getFileAsString("c:/tmp/t.in"); // table test contains two columns, first is varchar2 (256), second is a CLOB pstmt = dbconn.prepareStatement("insert into test values (?,?)"); pstmt.setString(1, chars.substring(128, 1)); pstmt.setString(2, chars.substring(128, 1)); pstmt.executeUpdate(); ResultSet rset = stmt.executeQuery("select * from test"); rset.next(); String newchars = rset.getString(1); Clob newcharsclob = rset.getClob(2); String newchars2 = newcharsclob.getSubString(1, (int)newcharsclob.length()); close(dbconn); System.out.println(newchars); System.out.println(newchars2); The first displays Euro, the second displays ? When I look at the data with Toad, database contains Euro in both fields, so I am guessing it's JDBC. I assume Toad uses some other database interface. "bung ho" <bung_ho (AT) hotmail (DOT) com> wrote in message news:567a1b1.0307141043.4186097a (AT) posting (DOT) google.com... woops. i don't know why it doesn't work for you then, it prints out the euro for me fine (and i have almost the exact same setup as you). maybe you should post your code (the CLOB insert as well as the retrieval and print statements) the fact that it's only 0x80-0x9f still makes me think it has something to do with Cp1252 vs. ISO-8859-1. "Ilia" <nospam (AT) deathtospam (DOT) com> wrote in message news:<zsDPa.101359$8B.52664 (AT) twister (DOT) nyroc.rr.com>... Thank you for your interest, here is more info: I run java program on Windows XP professional, JVM 1.3.1 with a -Dfile.encoding=ISO-8859-1 JVM parameter. Oracle server is running under Linux 7.3. With this parameter, code char c = 0x80 System.out.println(c); prints out a Euro symbol. You are right and the range is 0x80-0x9f. |
![]() |
| Thread Tools | |
| Display Modes | |
| |