• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dodgy behaviour in JDBC-ODBC Bridge

 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Discovered unusual behaviour in JDBC as implemented by the JDBC-ODBC Bridge. I was passing a hash value from Java code (Java type was long, SQL type was BIGINT) using the <code>setLong()</code> method of a CallableStatement object. Target was a SQL Server stored procedure, but I found that the resulting value in the database did not match the value being held on the Java side.
Further investigation revealed that the number was being held in JDBC as a float before being passed to the stored proc. Hence some bizarre rounding was taking place and the hash value was silently corrupted.
We got around this by converting the SQL type to binary and passing the hash in as a byte array using <code>setBytes()</code>.
My question is: has anybody else experienced this problem with the JDBC-ODBC bridge, and does it go away if you make the switch to a commercial type 4 driver?
Many thanks
Michael
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
[This message has been edited by Michael Fitzmaurice (edited August 25, 2001).]
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have some problems when I was using the jdbc-odbc bridge with java types of float, and I solved them changing the types to double, try it.
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcos
We weren't actually using floats at all, as I said the Java type was long, which was being converted (against our wishes) to a float by JDBC before being passed into a SQL Server stored procedure which expected a BIGINT. This behaviour was not something we expected to happen. There was no mention whatsoever of floats in our Java code.
The quickest, easiest and safest way around this seemed to be to convert to binary and pass that, which solved the problem. The main thing I am curious about is whether or not this problem occurs with other JDBC drivers. I know Sun themselves advise that the JDBC-ODBC bridge shouldn't really be used for any serious applications - is this one of the reasons?
[This message has been edited by Michael Fitzmaurice (edited August 26, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic