开发者

SQL query in Java throwing exception

I have some Java pulling from an Access database. Here's the code doing the querying:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "C:/Development/tomcat/webapps/inquire/inquire.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}";
Connection con = DriverManager.getConnection( database ,"","");
Statement s = con.createStatement();
s.execute ("SELECT manager FROM inquiries")开发者_如何学运维;
ResultSet rs = s.getResultSet();

Yes, there's a database named inquire.mdb at that location, with a table called 'inquiries' with a column named 'manager'

However, when the code executes I'm getting:

java.sql.SQLException: Column not found

It's really weird because in another place this query works:

String theQuery = "SELECT DISTINCT manager FROM inquiries";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String filename = "C:/Development/tomcat/webapps/inquire/inquire.mdb";
        String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
        database+= filename.trim() + ";DriverID=22;READONLY=true}";
        Connection con = DriverManager.getConnection( database ,"","");
        Statement s = con.createStatement();
        s.execute(theQuery);
        ResultSet rs = s.getResultSet();


Of course, as is almost always the problem when I run into a programming issue, it was something stupid I did.

The problem was in the processing of the resultset, not the query. I had simplified the query but was still using other columns in the processing. So yeah, of course it couldn't find the column, I wasn't even pulling it with my query.

If I wasn't stupid I would have printed the whole frigging stacktrace, not just the stupid exception.

Then I could find what line it was actially dying at.

Then it takes just a few seconds to fix.

Instead of, you know, HOURS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜