• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
}
}

}
}
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!