2013-10-04 28 views
-1

這裏是我的代碼我得到線程異常「主要」值java.sql.SQLException當我執行JDBC程序

import java.sql.*; 
import java.util.Scanner; 
class AccountDeletionApplication 
{ 
    public static void main(String[] args) throws ClassNotFoundException,SQLException 
    { 
     Scanner s=new Scanner(System.in); 
    System.out.println("Enter the Acc no:"); 
    int ano=s.nextInt(); 
    Class.forName("oracle.jdbc.driver.OracleDriver"); 
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger"); 
    Statement st=con.createStatement(); 
    int n=st.executeUpdate("delete from ACCOUNT1 where ACCNO="+ano); 
    if(n==1) 
     System.out.println("account deleted succesfully"); 
    else 
     System.out.println("account doesnt exist"); 
    st.close(); 
    con.close(); 
    } 
} 
+1

這是在查詢中使用字符串連接的不好做法。這可能會導致SQL注入...你應該準備語句..谷歌它..有很多例子:) – Anubhab

+1

請添加異常+ stacktrace到你的問題 –

回答

0

請張貼整個堆棧跟蹤,但最有可能你的驅動程序不上班級路徑。它不附帶JVM。去here下載它,並將其添加到你的類路徑。

+1

不,它是'SQLException'? – Husam

相關問題