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

Newbie problem. JDBC Error

chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
Hey guys,

I'm fairly new to java and jdbc, and I keep getting this SQL Error.
I can't seem to figure it out. Any help would be much appreciated.

Take care,

Chris



/*
* People2.java
*
* Created on August 18, 2004, 9:07 AM
*/

package dataTest;

import java.sql.*;


public class People2 {


//SET VARIABLES
private int id;
private String firstname;
private String lastname;
private String myStatement;


public static void main(String[] args)throws SQLException{

People2 p = new People2();

//SET CONNECTION OBJECTS
java.sql.Connection dbConn = null;
Statement myStatement = null;


//============ START DATABASE CONNECTION =============

try{

//LOAD THE DRIVER CLASS
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(Exception e){
System.out.println(e.getMessage());
}//end catch

//SET ODBC DATASOURCE
String dsSource = "jdbc dbc sJava";

//GET A CONNECTION TO THE DATABASE
dbConn = DriverManager.getConnection(dsSource);

//CREATE A STATEMENT OBJECT
myStatement = dbConn.createStatement();

//CREATE VARIBLE TO HOLD SQL COMMAND
String sqlString = "SELECT * FROM people";

//CREATE A RESULTSET
ResultSet myResultSet = myStatement.executeQuery(sqlString);

//SET VARIABLES TO RESULTSET VALUES
p.id = myResultSet.getInt("id");
p.firstname = myResultSet.getString("firstname");
p.lastname = myResultSet.getString("lastname");

while(myResultSet.next()){
System.out.println("ID: " + p.id);
System.out.println("FirstName: " + p.firstname);
System.out.println("LastName: " + p.lastname);
}//end while loop

//CLOSE ALL OBJECTS
myStatement.close();
dbConn.close();
myResultSet.close();


}//end main()

}//end class


--------- THIS IS THE ERROR I'M GETTING -------------

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'people'. Make sure it exists and that its name is spelled correctly.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at dataTest.People2.main(People2.java:55)
Exception in thread "main"
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, first the obvious question I have to ask since you didn't say one way or another. Are you sure there is a table called 'people' in the database? And is it the same case? Not People or PEOPLE?


GenRocket - Experts at Building Test Data
Mark Patrick
Ranch Hand

Joined: Feb 22, 2004
Posts: 51
You're getting a connection to the Access database without a problem. The error message is stating the Access cannot find a table or query in your database called 'people'. Are you sure that the table in the database is called 'people'?


Mark Patrick<br />SCJP 1.4
chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
I'm sorry, I posted the wrong error message.
It should read:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3812)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5642)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:585)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:603)
at dataTest.People2.main(People2.java:58)
Exception in thread "main"


--sorry about that
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Chris,

Slightly counter-intuitively you have to call myResultSet.next() before you can get the values from the first row with your getInt() and getString() calls. If you move the gets inside your while loop it should work fine.

Jules
chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
Thanks for responding!

Two questions:

1. Could you post a code sample? (still very new, and would like to compare with what I have)

2. It sounds like doing it that way will not allow me to set the variables to the result values and then print out values of the variables. Is this true?

Thank you all for your help!

Take care,

Chris
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I obviously didn't explain it very well. Here's the code snippet showing what I mean:

That's what I mean by moving the gets inside the while loop (remove them from where they currently are). Is that clear now?

Jules
chris le
Greenhorn

Joined: Jul 30, 2004
Posts: 15
That helped out alot. I appreciate all your help.
Take care,

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie problem. JDBC Error