Java - JDBC - deleteStatement
public void deleteStatement() throws SQLException {
Connection conn = DB_Util.getConn(DB_Types.MYSQLDB);
PreparedStatement pstmnt = null;
String sql = "Delete from City where ID = ?";
Scanner scanner = new Scanner(System.in);
System.out.print("Enter City ID: ");
int id = scanner.nextInt();
pstmnt = conn.prepareStatement(sql);
pstmnt.setInt(1, id);
int result = pstmnt.executeUpdate();
if(result == 1) {
System.out.println("City was successfully deleted!");
}
else {
System.out.println("City was not deleted!");
}
scanner.close();
pstmnt.close();
conn.close();
}