Exception in thread "main" java.lang.ClassCastException: org.apache.derby.client.am.Statement cannot be cast to java.beans.Statement
at CollegeLibrary.NotRegistered.DBStatement(NotRegistered.java:114)
at CollegeLibrary.NotRegistered.<init>(NotRegistered.java:85)
at CollegeLibrary.NotRegistered.main(NotRegistered.java:91)
Java Result: 1
with and err开发者_C百科or on the within these section
ResultSet SelectQuery(Statement st) {
ResultSet rs = null;
try {
rs = st.executeQuery("select * from APP.STUDENT");
} catch (SQLException ex) {
Logger.getLogger(NotRegistered.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
void InsertQuery(Statement st) {
try {
if(_txtFname.getText().length()>0 & _txtLname.getText().length()>0& _txtAddress.getText().length()>0&_txtPhone.getText().length()>0&_txtDob.getText().length()>0&_txtSTcode.getText().length()>0){
st.executeQuery("insert into APP.STUDENT values ('"+_txtFname.getText()+"','"+_txtLname.getText()+"','"+_txtAddress.getText()+"','"+_txtPhone.getText()+"','"+_txtDob.getText()+"','"+_txtSTcode.getText()+"')");
}else{
System.out.println("please fill up the form");
}
} catch (SQLException ex) {
Logger.getLogger(NotRegistered.class.getName()).log(Level.SEVERE, null, ex);
}
}
void UpdateQuery(Statement st) {
try {
if(_txtFname.getText().length()>0 & _txtLname.getText().length()>0){
st.executeUpdate("update APP.STUDENT SET USERNAME='"+_txtFname.getText()+
"', PASSWORD='"+_txtLname.getText()
+"' where USERNAME='"+_oldData+"'");
}else{
System.out.println("please fill up the form");
}
} catch (SQLException ex) {
Logger.getLogger(NotRegistered.class.getName()).log(Level.SEVERE, null, ex);
}
}
void DeleteQuery(Statement st) {
try {
if(_txtFname.getText().length()>0 & _txtLname.getText().length()>0& _txtAddress.getText().length()>0&_txtPhone.getText().length()>0&_txtDob.getText().length()>0&_txtSTcode.getText().length()>0){
System.out.println(" ");
st.executeUpdate("delete from APP.STUDENT where USERNAME='"+_oldData+"'");
}else{
System.out.println("please fill up the form");
}
} catch (SQLException ex) {
Logger.getLogger(NotRegistered.class.getName()).log(Level.SEVERE, null, ex);
}
}
java.lang.ClassCastException: org.apache.derby.client.am.Statement cannot be cast to java.beans.Statement
I think you have the wrong import
statement in your code.
There are java.sql.Statement (which you want here), and java.beans.Statement (which is something completely different).
I most cases, you want to use java.sql.PreparedStatement instead anyway, which steps around the name conflict, too. Don't put literal values directly in the SQL, use bind variables.
You should import
java.sql.statment not java.bean.statement
精彩评论