class dbtest
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (java.lang.Exception ex1)
{
//ex1.printStackTrace();
System.out.println( "Error: Could not load Sun
ODBC driver" );
}
try
{
Class.forName
("com.ms.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println( "MS ODBC Driver loaded" );
}
catch (java.lang.Exception ex2)
{
//ex2.printStackTrace();
System.out.println( "Error: Could not load MS
ODBC driver" );
}
try
{
Connection conn = DriverManager.getConnection
("JDBC:ODBC:bcs www","password","password");
PreparedStatement statement =
conn.prepareStatement("select * from Users where UserId = '5002883'");
// Try 1
ResultSet rs = statement.executeQuery();
while( rs.next() )
{
// Do nothing
}
// Try 2. Sun JDK 1.2.1 errors out here. MS 3.2
SDK's JVM does not
rs = statement.executeQuery();
while( rs.next() )
{
// Do nothing
}
conn.close();
}
catch( Exception ex3 )
{
ex3.printStackTrace();
}
}
}
This works with the MS JVM, but Sun gives:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid
cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:4089)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:4246)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:1211)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute
(JdbcOdbcPreparedState
ment.java:202)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery
(JdbcOdbcPrepared
Statement.java:105)
at dbtest.main(dbtest.java:41)
Anyone have any ideas on how to get around this? The only way I know is
to close and re-open the connection.
paul (at) cravenfamily.com
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
Still doesn't work. Actually I found out that it is a known bug:
http://developer.java.sun.com/developer/bugParade/bugs/4191587.html
...and one of the people on the comments has a fix for it. But you have
to edit rt.jar. I'm having problems getting a decompiler that will
decompile the proper class so that I can insert the fix.
Joe Weinstein at BEA, the home of WebLogic
pcr...@my-deja.com wrote:
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---
--
PS: Hey folks, we're hiring Java engineers for our WebLogic
Engineering group in downtown S.F. Send me your resume.
--------------------------------------------------------------------------------
The Weblogic Application Server from BEA
JavaWorld Editor's Choice Award: Best Web Application Server
Java Developer's Journal Editor's Choice Award: Best Web Application Server
Crossroads A-List Award: Rapid Application Development Tools for Java
Intelligent Enterprise RealWare: Best Application Using a Component Architecture
http://weblogic.beasys.com/press/awards/index.htm
Workaround: After using the PreparedStatement, close it and discard it, then
recreate it next time you want to use it. No need to close the connection.
Joseph Weinstein wrote in message <374D8677...@weblogic.com>...
Harry Chomsky пишет в сообщении
<2_f33.1122$kd5.1...@typhoon-sf.snfc21.pbi.net> ...
>I encountered this bug even when I did call rs.close(). I think it's a bug
>in the JDBC-ODBC driver that comes with JDK 1.2 (and 1.2.1). Never had the
>problem with JDK 1.1.x. The problem happens only with PreparedStatement,
>not with Statement. Note that Sun considers the JDBC-ODBC driver "not an
>officially supported product", so it's likely to have bugs like this...
>
>Workaround: After using the PreparedStatement, close it and discard it,
then
>recreate it next time you want to use it. No need to close the connection.
You are not alone. This is a registered bug (numbers 4101823 and 4191587),
and first was registered Jan 5 1998. One wise guy even found how to fix that
bug
by decompiling class file and adding only ONE line to source. I don't know,
why Sun not include that fix into JDK.
Regards,
Sergey Astakhov (ser...@comita.spb.ru)
COMITA Ltd.