I am trying to pass a SQL command where a row has to be deleted from the database. I m using setString(index, value) and invoking the method in the main class. But when I pass the parameter to the method in the main class nothing happens in the database. Is there a form to pass the value of "jobnumber=?" in the main method so it deletes that row from the database? Ps: jobnumber is declared as serial and is the primary key in the database.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DeleteUserDao {
Connection conDB2 = Connect.connectDB();
public void deleteDb(String y) {
String sqlDelete = ("DELETE FROM bookings WHERE jobnumber=?");
try {
PreparedStatement deleter = conDB2.prepareStatement(sqlDelete);
deleter.setString(1, y);
System.out.println("Item deleted from Bookings.");
} catch (SQLException e) {
System.out.println("Coud not delete item. " + e.getMessage());
e.printStackTrace();
}
}
}
import ***.jdbc.DeleteUserDao;
public class DeleteTest {
public static void main(String[] args) {
DeleteUserDao del = new DeleteUserDao();
del.deleteDb("4");
}
}