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
與和錯誤在這些區間內以下SQL子句
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);
}
}
這是當你讓你的IDE選擇進口不看,看它選擇哪一個會發生什麼。 – 2010-12-17 01:34:27
然而,在現實生活中,您很快就會發現,您想調用「聲明」的方法都不存在。我想知道他爲什麼首先添加演員。你得到一個Statement的地方都會返回一個java.sql.Statement,而且他顯示的方法似乎也導入了正確的方法(它們有一個返回ResultSet的executeQuery)。我不記得曾經必須對陳述進行明確的轉換。 – Thilo 2010-12-17 01:40:53
謝謝你們我試圖導入java.sql.statement,但仍然遇到同樣的問題 – dnyondo 2010-12-17 01:52:53