aspose file tools*
The moose likes JDBC and the fly likes an illigal cursor status. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "an illigal cursor status." Watch "an illigal cursor status." New topic
Author

an illigal cursor status.

Levien de Reu
Greenhorn

Joined: Nov 28, 2004
Posts: 3
Hello

Can anyone give me al clue?
I want to execute a the following query on an MS access DB via jdbc-odbc bridge
Class.forName(DRIVER);
Connection con = DriverManager.getConnection(URL);
Statement st = con.createStatement();
con.setAutoCommit(true);
ResultSet rs = st.executeQuery("SELECT MAX(persId) FROM Persoon");
System.out.println(rs.getInt("persId"));

I would like it to return the max value of the int persId.
But i get an 'Illigal cursor status' (SQLException id=43).
I'm working with tomcat 5.0 and eclipse.

I hope someone knows what i'm doing..............wrong.

thanks

Levien.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Levien de Reu!

I'm moving this to the JDBC forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30922
    
158

Levien,
Since you are using an aggregate function (max), the column name is not defined. You have two choices:

1) Use a column number:

2) Give the column a name:


Also make sure you are calling rs.next() before accessing the column. Otherwise, the cursor is pointing to a position before that of the result.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Levien de Reu
Greenhorn

Joined: Nov 28, 2004
Posts: 3
Jeanne,

Many Thanx, it works !
Except the get method, i used a getInt.
But i assume that was what you ment.




bye
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30922
    
158

Yes, I meant getInt(). Glad to hear you have it working.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: an illigal cursor status.