我正在嘗試爲此按鈕編寫一個函數。我希望能夠傳遞一個文本域的值,並能夠進入我的數據庫檢索一些信息.....Oracle Java SQL異常錯誤:ORA-0094
有人可以向我解釋發生了什麼,併爲我提供了一個解決這個瘋狂?
謝謝大家的xD
我一直運行到這個愚蠢的問題:
ACTION1 [email protected]
Exception:java.sql.SQLSyntaxErrorException: ORA-00904: "ART": invalid identifier
代碼:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//CLASS TYPE
//LIST ALL OFFERED CLASSES AND REVENUE
try{
String classtype = jTextField1.getText().trim();
if(classtype.equals("")){
JOptionPane.showMessageDialog(this, "Sorry Wrong input.... Please try again....");
}
else if(classtype != ""){
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(
"jdbc:oracle:thin:@fourier.cs.iit.edu:1521:orcl",
"usr","pwd");
Statement stmt = conn.createStatement();
System.out.println("ACTION1 created"+conn+"\n\n");
String ct = jTextField1.getText().trim();
//String aa = "SELECT * FROM CLASS WHERE TYPE="+classtype;
//System.out.println(aa);
ResultSet rset = stmt.executeQuery("SELECT * FROM CLASS WHERE TYPE="+ct);
while (rset.next()) {
System.out.println(rset.getString("TITLE") + " ");
}
JOptionPane.showMessageDialog(this, "Class Type: "+classtype);
stmt.close();
conn.close();
System.out.println("Connection Closed");
}
catch(Exception sqle){
System.out.println("\nException:"+sqle);
}
}
}
catch(Exception e){
JOptionPane.showMessageDialog(this, "Please Retry input....", "Error", JOptionPane.ERROR_MESSAGE);
}
}
您的文本框的內容添加到您的SQL字符串(絕對NOGO SQL注入漏洞!),那麼什麼是'ct'的內容時,會拋出異常? – 2012-03-01 09:04:56
as @Andreas_D表示您沒有使用準備好的語句。但無論如何,如果你連接一個字符串,它需要在兩個'''內,'''SELECT * FROM CLASS WHERE TYPE ='「+ ct +」'「'(但更好的解決方案是將params添加到準備好的語句 – 2012-03-01 09:14:12