PDA

View Full Version : Reading backslashes from a JDBC String


rcovington
09-04-2003, 04:59 AM
I am accessing an Oracle database using the thin JDBC driver which has a column in a table that contains a valid Windows path full of backslashes (ie. C:\Windows\notepad.exe).

When I read this column from my resultset the .getString method like all good String objects converts the backslashes to the special characters represented by them. (resulting in C:Windowsnotepad.exe).

Unfortunately, in this case, I do not have "control" of the application writing to this database so I cannot have it convert the single backslashes to double backslashes when it stores the string.

What is the best way for me to read a "raw" string from a Text column and NOT have it interpret the backslashes?

I appreciate any help anyone can provide.

Take care *** Bobc

Dru Lee Parsec
09-04-2003, 12:59 PM
Interesting situation.

I'm not sure if any of these ideas will work for sure, but you might try
public InputStream getAsciiStream(int columnIndex) from the ResultSet object. If that doesn't work then maybe public InputStream getBinaryStream(int columnIndex) could work. Then you could do the conversion from \ to \\ yourself.

If neither of those work then I'm pretty sure that public byte[] getBytes(int columnIndex) would work. That would give you an array of bytes which you can walk through and add a backslash.

Once you have the byte array you can just use the String object constructor public String(byte[] bytes) to instanly convert back to a String.

Hope it helps.

rcovington
09-06-2003, 01:50 AM
I tried using getBytes and I still have the problem. It's almost like the Oracle JDBC driver is converting it to a Java String before I can get to the data.

*** Bobc