I finally was able to get a connection to my access database. It will print one row of data and stop, I know there is at least 3 lines of data to print.
If I use while(rs.next()); it does not print any of the data. If I remove the while, it will print one record. Can anyone tell me what I am doing wrong??
/**
*
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; //This is where I am setting the variable
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("sun.jdbc.odbc.JdbcOdbcDriver");
//Connect
Connection conn = DriverManager.getConnection(url,"","");
System.out.println("Class Found");
stmt = conn.createStatement();//Create Statement Object
ResultSet rs = stmt.executeQuery(sql);
(rs.next());//only one row of data prints
// while (rs != null);{ when I do this none of the data prints
//get informatoin and load into variables
int qID = (rs.getInt("qID"));
String qText = (rs.getString("qText"));
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);
rs.close();
}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);
}
}
}