Two Laptop Bag*
The moose likes JDBC and the fly likes JDBC-ODBC does not work for long datatypes using prepared statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC-ODBC does not work for long datatypes using prepared statements" Watch "JDBC-ODBC does not work for long datatypes using prepared statements" New topic
Author

JDBC-ODBC does not work for long datatypes using prepared statements

Suren Babu
Greenhorn

Joined: Oct 23, 2000
Posts: 27
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] ) ;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc dbc ubdb", "sa", "");
testSampleDB() ;
}
public static void main(String[] args) throws Exception
{
new TestJDBCODBC( args );
}

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

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

ResultSet rset1 = pstmt.executeQuery();

if(rset1!=null)
{
//System.out.println("resultset is NOT null: " + rset1);
while(rset1.next())
{
System.out.print(rset1.getLong(1) +", ");
System.out.println(rset1.getString(2));
}
}

}
}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
Dave.
Suren Babu
Greenhorn

Joined: Oct 23, 2000
Posts: 27
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.
Thanks
 
GeeCON Prague 2014
 
subject: JDBC-ODBC does not work for long datatypes using prepared statements