Thread: RE: JDBC driver writes binary data ONLY as Large Obj ect
Hmmm, I see your point. There must be some way of encoding the string so that the data is stored correctly. I know certain control characters can be stored (cr/lf's etc) as I have a PHP script that does it here. Is it the new String(bytes[]) bit that barfs, or is it that the data is mungled when it's re-read from the table? Peter -- Peter Mount Enterprise Support Maidstone Borough Council Any views stated are my own, and not those of Maidstone Borough Council -----Original Message----- From: Bill [mailto:bouma@cplane.com] Sent: Wednesday, August 02, 2000 8:57 PM To: Peter Mount Cc: pgsql-interfaces@postgresql.org Subject: Re: [INTERFACES] JDBC driver writes binary data ONLY as Large Object Peter Mount wrote: > The problem here is that there is no metadata available to check. > > If the backend was able to precompile the query, then we would know the > column type, but as it stands currently there is no way of finding out what > the column type is. > > Peter Ok. Suppose there was metadata available. How would you rewrite the function PreparedStatement.writeBytes() such that it writes the bytes directly into the column? Since that class does everything through heavy use of String manipulation, I can't see how to do it. Is there a way? I tried this: public void setBytes(int parameterIndex, byte x[]) throws SQLException { set(parameterIndex, new String(x)); } It barfed. Bill
Peter Mount wrote: > Hmmm, I see your point. There must be some way of encoding the string so > that the data is stored correctly. I know certain control characters can be > stored (cr/lf's etc) as I have a PHP script that does it here. > > Is it the new String(bytes[]) bit that barfs, or is it that the data is > mungled when it's re-read from the table? ------------------------------------------- java.sql.SQLException: ERROR: parser: parse error at or near "" at org.postgresql.Connection.ExecSQL(Connection.java, Compiled Code) at org.postgresql.jdbc2.Statement.execute(Statement.java,Compiled Code) at org.postgresql.jdbc2.Statement.executeUpdate(Statement.java:73) at org.postgresql.jdbc2.PreparedStatement.executeUpdate(PreparedStatement.java:126) ------------------------------------------- Perhaps we can look at the ResultSet.getBytes() and just do the inverse of that? Though I haven't tested if getBytes() is doing the right thing yet, either. In the end I need to be able to store/retrieve the data through both JDBC and ODBC interface. This is working now if I store all binary data as Large Objects. But most of my blobs of binary are only 200-2000 bytes long. I assume it is much less efficient to store such small blobs as LOs? That is, assuming the driver code is written well. So that may not be true with the current JDBC driver given that it would first have to convert the binary blob into a String. 8^( Bill