-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();
}
沒有太多去。你的桌子是什麼樣的?你試圖插入什麼數據? –
可能希望將println移動到嘗試的第一行以查看數據是否不正確 – Tibrogargan
請參閱Java文檔http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html – Unknown