JDBC reading data from database table that contains control characters
I have the following bit of code that reads data from the an Oracle table (Note: This is running on Jdk 1.4.2)
ResultSet message = messageStatement.executeQuery(getMsgSql);
String messageData = message.getString("MESSAGE_DATA");
The data in the MESSAGE_DATA column contains text but also control characters that separate data elements in the message (i.e (char)31, (char)29) and (char)28) .
What i am finding is that for some reason message.getString() is sometimes truncating the message. I can read the majority of messages but some of them are truncated. Am i supposed to be reading the data using a different method? If so how?
I have tried to use sqlplus to look at the data in the database and it is all there it is just truncated by the message.getString() method. I saw this when i tried to output t开发者_运维知识库he result i.e. System.out.println(message.getString()).
Thanks
Update
I ran an sql query using the length() function in Oracle and length("MESSAGE_DATA") returns 2032 whereas in java message.getString(1).length() returns 2000. Im not sure why this is happening.
Update
Ok i might be on to something i think. I just tried a newer version of the JDBC driver and it seems to be working. The driver that was being used was an older version that was delivered for the jdk1.4 delivery. Does anyone know why this is the case? And also, does using a newer version of the jdbc driver have any implications especially given the fact that the application is running on JDK 1.4. The oracle version is 10.1.0.3.0
Update
I am not sure if this is any helpfull but here are the versions of the two JDBC drivers.
The JDBC driver that does not work
===== Database info =====
DatabaseProductName: Oracle
DatabaseProductVersion: Oracle Database 10g Release 10.1.0.3.0 - 64bit Production
===== Driver info =====
DriverName: Oracle JDBC driver
DriverVersion: 8.0.5.2.0
DriverMajorVersion: 8
DriverMinorVersion: 0
The JDBC Driver that does work
===== Database info =====
DatabaseProductName: Oracle
DatabaseProductVersion: Oracle Database 10g Release 10.1.0.3.0 - 64bit Production
===== Driver info =====
DriverName: Oracle JDBC driver
DriverVersion: 10.2.0.1.0
DriverMajorVersion: 10
DriverMinorVersion: 2
Thanks
My guess: database has a non-default charset. If Java driver is unaware of that charset, it will expect the default (whatever it is), and do a decoding wrong, sometimes possible truncating the string.
精彩评论