JDBC stmt.set.BinaryStream and stmt.setBytes (repost)
Posted in 2000
Topics: Connectivity: ODBC / JDBC / .NET, Platform-Specific Issues, Java & JDBC Development
Hi, As far as I've been, I haven't been able to find a real difference between stmt.set.BinaryStream and stmt.setBytes in a java query to a IDS 2000 server (9.20) on Solaris 2.6. I've gone through th Informix JDBC Driver's programmer's guide, without finding anything. It seems both are working. Maybe one of this function is newser or faster to run ? Maybe the connection to the database or the lock lever is not the same ? any clue ? -- _______________________________________________ Sebastien THOMAS none networks System Engineer freesbee geo:153, rue Saint-Denis, 75002 Paris, France vox:+33 1 45 08 23 10 - fax:+33 1 45 08 25 29 mailto:sebastien.thomas@none.net
According to the JDBC 2.0 spec, the JDBC driver uses the set.BinaryStream() to convert to a LONGVARBINARY, while with the setBytes() method the driver has the choice of either VARBINARY or LONGVARBINARY. I am unclear on any practical implications of that choice. Perhaps someone can enlighten me? HTH Cheers-- Charles Sebastien THOMAS <Sebastien.THOMAS@none.net> wrote in article <39FE97B3.F9B2F05D@none.net>... > Hi, > > As far as I've been, I haven't been able to find a real difference > between stmt.set.BinaryStream and stmt.setBytes in a java query to a IDS > > 2000 server (9.20) on Solaris 2.6. > I've gone through th Informix JDBC Driver's programmer's guide, without > finding anything. > It seems both are working. Maybe one of this function is newser or > faster to run ? > Maybe the connection to the database or the lock lever is not the same ? > > any clue ? > > -- > _______________________________________________ > Sebastien THOMAS none networks > System Engineer freesbee > > geo:153, rue Saint-Denis, 75002 Paris, France > vox:+33 1 45 08 23 10 - fax:+33 1 45 08 25 29 > mailto:sebastien.thomas@none.net > > > >
G'day I would guess that you would use PrepearedStatement.setBinaryStream to directly read from an InputStream ( a file ) and put it into a database column, where PreparedStatement.setBytes would be used if your program created the data. --- from Java API Docs --- setBinaryStream public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException Sets the designated parameter to the given input stream, which will have the specified number of bytes. When a very large binary value is input to a LONGVARBINARY parameter, it may be more practical to send it via a java.io.InputStream. JDBC will read the data from the stream as needed, until it reaches end-of-file. Note: This stream object can either be a standard Java stream object or your own subclass that implements the standard interface. Parameters: parameterIndex - the first parameter is 1, the second is 2, ... x - the java input stream which contains the binary parameter value length - the number of bytes in the stream Throws: SQLException - if a database access error occurs setBytes public void setBytes(int parameterIndex, byte[] x) throws SQLException Sets the designated parameter to a Java array of bytes. The driver converts this to an SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARYs) when it sends it to the database. Parameters: parameterIndex - the first parameter is 1, the second is 2, ... x - the parameter value Throws: SQLException - if a database access error occurs ---- I guess that it would be most appropriate if it was an INSERT or UPDATE prepared statement. Regards Kelly Sebastien THOMAS wrote: > > Hi, > > As far as I've been, I haven't been able to find a real difference > between stmt.set.BinaryStream and stmt.setBytes in a java query to a IDS > > 2000 server (9.20) on Solaris 2.6. > I've gone through th Informix JDBC Driver's programmer's guide, without > finding anything. > It seems both are working. Maybe one of this function is newser or > faster to run ? > Maybe the connection to the database or the lock lever is not the same ? > > any clue ? > > -- > _______________________________________________ > Sebastien THOMAS none networks > System Engineer freesbee > > geo:153, rue Saint-Denis, 75002 Paris, France > vox:+33 1 45 08 23 10 - fax:+33 1 45 08 25 29 > mailto:sebastien.thomas@none.net