Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

String car_id = combocarID.getSelectedItem().toString();

String cust_id = txtcust_id.getText();
String fee = txtrentalfee.getText();

SimpleDateFormat Date_Format = new SimpleDateFormat("yyyy-MM-dd");
String date = Date_Format.format(txtdate.getDate());

SimpleDateFormat Date_Format1 = new SimpleDateFormat("yyyy-MM-dd");
String due = Date_Format1.format(txtdate.getDate());

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=MyProject;user=MyAdmin;password=123456789");
pst3 = con.prepareStatement("INSERT INTO Rental (CAR_ID,CUSTOMER_ID,FEE,DATE,DUE) VALUES(?,?,?,?,?)");
pst3.setString(1, car_id);
pst3.setString(2, cust_id);
pst3.setString(3, fee);
pst3.setString(4, date);
pst3.setString(5, due);
pst3.executeUpdate();


pst4 = con.prepareStatement("UPDATE CarRegistration SET AVAILABLE='No' WHERE
CAR_NO ");


pst4.setString(1,car_id);
pst4.executeUpdate();

What I have tried:

i tried to change the index no but still getting the error at pst4.setString(1,car_id)
Posted
Updated 12-Jan-20 22:26pm

1 solution

Look at your code:
pst4 = con.prepareStatement("UPDATE CarRegistration SET AVAILABLE='No' WHERE
CAR_NO ");


pst4.setString(1,car_id);
The SQL contains no parameters (or even a valid SQL WHERE clause) - which is why index 1 doesn't exist. Perhaps you meant this:
pst4 = con.prepareStatement("UPDATE CarRegistration SET AVAILABLE='No' WHERE
CAR_NO = ?");


pst4.setString(1,car_id);
 
Share this answer
 
Comments
Kurt Jimenez 13-Jan-20 4:33am    
Yes you're right bruh, sorry I forgot to include that,, thank you!
OriginalGriff 13-Jan-20 4:49am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900