This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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 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:;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 ( {
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:
subject: Code works in main() but not in a handler
It's not a secret anymore!