i am getting error as following code in java file name javaDAO try to call a method from jbutton. in my javaDAO file 3 method is define 1.extablishConnection 2.retriveName 3.CloseConnection at time of getting userName and password from .access file it gives following errors
Dec 8, 2013 11:31:59 AM vuAssignment.JFrame jButton1ActionPerformed
SEVERE: null
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3149)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute
(JdbcOdbcPreparedStatement.java:216)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery
(JdbcOdbcPreparedStatement.java:91)
at vuAssignment.javaDAO.retrieveName(javaDAO.java:33)
at vuAssignment.JFrame.jButton1ActionPerformed(JFrame.java:139)
Code in javaDAO file is which is call by main method in JFrame.java in netbeans IDE
//method to establish connection
private void establishConnection() throws ClassNotFoundException,SQLException{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:ProductDb";
Class.forName(driver);
con = DriverManager.getConnection(url);
}
// method to call query
public void retrieveName(String pName,String pWord) throws
ClassNotFoundException,SQLException{
String user1= "";
String pass1 = "";
String sql = "SELECT * FROM admin where userName= ? && password= ?";
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet res = stmt.executeQuery();
while (res.next()) {
user1 = res.getString("userName");
pass1 = res.getString("password");
}
if (pName.equals(user1) && pWord.equals(pass1))
JOptionPane.showMessageDialog(null,"correct");
else
JOptionPane.showMessageDialog(null,"incorrect");
Check out with your code. Here is something missing.
Put at right place, after the con.prepareStatement.