Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code works in main() but not in a handler

 
Joe Kaz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
Joe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic