Forums Register Login
JDBC-ODBC does not work for long datatypes using prepared statements
Database: MS SQL 2000
Platform: Windows 2000 sp2, Windows NT sp6a
Protocol to DB: TCPIP
JDBC-ODBC does not work for long datatypes using prepared statements. I use sample database pubs for this. I have a created table called base...
create table base
( id$ bigint, name varchar(80) )
where i inserted couple of rows with id$ containing values ranging from 2^8, 2^16, 2^31, 2^32, 2^63.
Executing the following code for id$ values less than 2^31 works fine. Exceeding that range didn't return me any rows even though i have rows in table.
Here is the code...
import java.sql.*;
import java.io.*;
public class TestJDBCODBC
Connection conn = null ;
long rowCnt = 0;
public TestJDBCODBC( String args[] ) throws Exception
rowCnt = Long.parseLong( args[0] ) ;

conn = DriverManager.getConnection("jdbc dbc ubdb", "sa", "");
testSampleDB() ;
public static void main(String[] args) throws Exception
new TestJDBCODBC( args );

public void testSampleDB() throws Exception
s //String Query = "SELECT rowcnt FrOM sysindexes where rowcnt=?";
String Query = "SELECT id$, name FrOM base where id$=?";

PreparedStatement pstmt = conn.prepareStatement(Query);
pstmt.setLong( 1, rowCnt ) ;

ResultSet rset1 = pstmt.executeQuery();

//System.out.println("resultset is NOT null: " + rset1);
System.out.print(rset1.getLong(1) +", ");

Correct, it doesn't work for get/setLong etc.
Use get/setString for all your calls instead.
I'm pretty sure this has worked me in the past.
Thanks a lot Dave ...
Need some more clarifications regarding this...
1\ Moving setLong to setString works for all databases?. Our product supports Sybase, Oracle , MSSQL.
2\ Any idea how reliable is Sun's JDBC-ODBC Driver. Shall we go ahead with this for product based development.
3\ Do you know any URLs which has all the known issues / defects in Sun's JDBC-ODBC bridge.
get schwifty. tiny ad:
Why should you try IntelliJ IDEA ?

This thread has been viewed 1506 times.

All times above are in ranch (not your local) time.
The current ranch time is
Aug 16, 2018 18:20:26.