Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException: Invalid cursor position

807591Apr 6 2008 — edited Apr 7 2008
Well I am not sure what the problem is. I have run this query hundreds of times and now it doesn't seem to work, but I do change them from time to time so maybe I changed this one in some way.... The odd thing is when I run the query in SQL Management Studio it works perfect...?

Anyways here is my Trace:
java.sql.SQLException: [Microsoft][SQL Native Client]Invalid cursor position
	at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
	at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
	at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
	at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
	at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
	at executeQuery.executeSQLQuery(executeQuery.java:26)
	at JRSMedia.getAlbums(JRSMedia.java:227)
	at JRSMedia.mainWindow(JRSMedia.java:20)
	at Driver.main(Driver.java:5)
Here is my Query:
SELECT AlbumName FROM Song_Details left outer join Song_Album on Song_Details.Song_ID = Song_Album.Song_ID left outer join Album on Song_Album.Album_ID = Album.Album_ID;
Here is my code to execute the query:
// The query I pass in is above.
// the RowCount I pass in is 78 which there are 78 values in the database.
// and colInt is 1 <-- which essentialy means it selects column 1.

public class executeQuery {
	
	public static String[] executeSQLQuery(String query, int rowCount, int colInt) {
		JRSMedia mainObj = new JRSMedia();
		int i = 0;
		String[] values = new String[rowCount+1];
		try {
	        // Load the JDBC driver. 
	       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
	        // Establish the connection to the database. 
	        Connection conn = JRSMedia.connectToDatabase();
	        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
				if (conn.isClosed() == true){
					//Launch an error message!
				}else{
					ResultSet rs = stmt.executeQuery(query);
					while(rs.next()) {        
						System.out.println(i);
						values[i] = rs.getString(colInt);
						i++;
			        }
				}
			conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
				mainObj.throwDatabaseConnectionError();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				mainObj.throwJDBCError();
			}   	
		return values;
	}
}
Any help is greatly appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2008
Added on Apr 6 2008
4 comments
1,216 views