aspose file tools*
The moose likes JDBC and the fly likes HELP! Connection to MS Access DB Trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "HELP! Connection to MS Access DB Trouble" Watch "HELP! Connection to MS Access DB Trouble" New topic
Author

HELP! Connection to MS Access DB Trouble

Kassi Hill
Greenhorn

Joined: Sep 29, 2003
Posts: 24
I need help. I am trying to connect to a Access database class. I know there is some test data in the table that I am trying to select from but when I run the program I get a error message that says: SQLE NOT EXECUTED: No Row Count Produced.
I have put my code below hoping maybe one of you more experienced ranchers can he me out. Thank you.
package testbanktesting;
/**
* Testing Classes
* @version 1.0
*/
import java.sql.*;
import java.io.*;
public class DataAccess {
private final String url = "jdbc dbc:TestBank";
private final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
private Connection conn;
private ResultSet rs;
private Statement stmt;
public DataAccess() {
}
private void openConnection ()throws ClassNotFoundException{
//this is the method used to connect to the database using hte JDBC dbc bridge
String sql = "SELECT * FROM Question";
try{
//load the driver
Class.forName(driver);
//Connect
conn = DriverManager.getConnection(url,"","");
stmt = conn.createStatement();//Create Statement Object
stmt.executeUpdate(sql);
// boolean returnsResultSet = stmt.execute(sql);
while (rs.next()); //get informatoin and load into variables
int qID = (rs.getInt("qID"));
String qText = (rs.getString("qText"));
// boolean qType = (rs.getBoolean("qType"));
String qType =(rs.getString("qType"));
int qCorrect = (rs.getInt("qCorrect"));;//chek for results and add them to result set.
System.out.println(qID);
System.out.println(qText);
System.out.println(qType);
System.out.println(qCorrect);

}catch(SQLException sqle) {
System.err.println("SQL NOT Executed: " + sqle);
}catch(java.lang.Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
DataAccess dataAccess1 = new DataAccess();
try{
dataAccess1.openConnection();
}catch(Exception sqle) {
System.err.println("SQL NOT Executed: " + sqle);
}
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8


Two things in two lines. First, you aren't executing a SQL UPDATE, so you should use Statement.executeQuery. Second, where do you set the variable rs?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Kassi Hill
Greenhorn

Joined: Sep 29, 2003
Posts: 24
I had been setting the variable rs as a member variable at the top:
private ResultSet rs
I did this because when I finall get this to work, it will be the "DataAccess" class for a larger program that will be using a three tiered approach, where other classes will call for the information they need so the class will need to return an result set, which is way I had originally written it as a member variable.
I am now getting an invalid curser position message. Java really hates me.
Thank you for your help!!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

Originally posted by Kassi Hill:

I am now getting an invalid curser position message. Java really hates me.

Java doesn't hate you. It is simply particular about how it is used.
Again, where do you set the variable rs to a usable value?
Kassi Hill
Greenhorn

Joined: Sep 29, 2003
Posts: 24
I am sorry for going on before. I am setting the ResultSet var as a private ResultSet rs in the start of the class, at the very top. Is it okay to define it here?? or now that I think about it, I am defining it at the top but not setting it any where, is this my problem??
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8867
    
    8

 
 
subject: HELP! Connection to MS Access DB Trouble