2016-08-25 46 views
-2
try{ 
     PreparedStatement pst=con.prepareStatement("INSERT INTO employee_details (E_NAME,E_PASSWORD,E_USERNAME,E_CONTACT," 
       + "E_ROLE) VALUES (?,?,?,?,?);"); 
     state=1; 

     pst.setString(1,employee.getEname());//Step 7: calling getter() from getter/setter class 
    //Step 10: setting getter values to corresponding query 
     pst.setString(2,employee.getPass());//Step 7: calling getter() from getter/setter class 
      //Step 10: setting getter values to corresponding 
     pst.setString(3,employee.getUname());//Step 7: calling getter() from getter/setter class 
      //Step 10: setting getter values to corresponding 
     pst.setString(4,employee.getEcontact());//Step 7: calling getter() from getter/setter class 
      //Step 10: setting getter values to corresponding 
     pst.setInt(5,employee.getUrole());//Step 7: calling getter() from getter/setter class 
      //Step 10: setting getter values to corresponding 
     pst.executeQuery(); 
     System.out.println("name:"+employee.getEname()+" pass:"+employee.getPass()+" uname:"+employee.getUname()+" con:"+employee.getEcontact()+" role:"+employee.getUrole()); 

    } 
    catch(SQLException e){ 
     e.printStackTrace(); 
    } 
+1

沒有太多去。你的桌子是什麼樣的?你試圖插入什麼數據? –

+0

可能希望將println移動到嘗試的第一行以查看數據是否不正確 – Tibrogargan

+0

請參閱Java文檔http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html – Unknown

回答

0

在準備語句末尾有一個不需要的分號,請將其刪除。

試試這個

PreparedStatement pst=con.prepareStatement("INSERT INTO employee_details (E_NAME,E_PASSWORD,E_USERNAME,E_CONTACT," 
       + "E_ROLE) VALUES (?,?,?,?,?)"); 

代替

PreparedStatement pst=con.prepareStatement("INSERT INTO employee_details (E_NAME,E_PASSWORD,E_USERNAME,E_CONTACT," 
       + "E_ROLE) VALUES (?,?,?,?,?);"); 
相關問題