I am facing the above-mentioned error in the following code. Please help me to fix this.
private void But_AddIncomeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=DB_Project;user=User;Password=password";
Connection con= DriverManager.getConnection(url);
String query = "insert into tbl_Reg(FullName,CNIC,Email_Address,Pswd,Adrs,PhoneNo)values(?,?,?,?,?,?)";
PreparedStatement pst=con.prepareStatement(query);
pst.setString (1,((JTextField)DateChooser.getDateEditor().getUiComponent()).getText());
pst.setString(2,Amnt_TF.getText());
pst.setString(3,Src_TF.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"Income Detail Updated");
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
Your query has 6 parameters (6 ?
in SQL) but you set only 3 (with setString()
method). You need to set all 6 to avoid this exception.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.