wood burning stoves 2.0*
The moose likes JDBC and the fly likes Code works in main() but not in a handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Code works in main() but not in a handler " Watch "Code works in main() but not in a handler " New topic

Code works in main() but not in a handler

Joe Kaz

Joined: Aug 13, 2001
Posts: 14
I was am successfully retrieving DB table names from a local MS Access 2000 database with the code below in main(). However when I simply paste the exact same code into an actionPerformed() handler method, it generates this SQLException at the getString() statement:
[Microsoft] {ODBC Driver Manager] Invalid cursor state
The driver name is odbcjt32.dll v 2.0001 <04.00.4403>
I have tried playing around with repositioning the cursor first,
creating another connection first, and have tried other suggestions posted on various ODBC discussion boards for this error, but you really can't do much when using DatabaseMetaData. Again, I get all the way to the first getString() successfully and have determined that rs.next() is returning 'true' OK.
Microsoft has posted some admitted odbc bugs for this type of error regarding threading possibilities, which I think may be coming into play here once I move the code out of main()... I don't know... The most relevant MS notes on this may be at this URL: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q253010
Thanks all, for any insights here.
Joe Kaz
Here's the code:
Connection connection = DriverManager.getConnection("jdbc dbc:MyDSN");
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet rs = dbmd.getTables( n,n , "%", m );
while (rs.next()) {
System.out.println("Table = " + rs.getString(3) );
Joe Kaz

Joined: Aug 13, 2001
Posts: 14
Another point on that main() code:
I can successfully move from main() to the handler method any code creating ResultSets from regular Statements. This problem is just with the result set created from the DatabaseMetaData object.
I agree. Here's the link: http://aspose.com/file-tools
subject: Code works in main() but not in a handler
Similar Threads
Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver f
is there any limitation for parameter carrying ?
IIS server
Disabling Cookie in IE 6
WS4.0 Admin server error 1053