Deleting a Row from a Database Table

try { // Create a statement Statement stmt = connection.createStatement(); // Prepare a statement to insert a record String sql = "DELETE FROM my_table WHERE col_string='a string'"; // Execute the delete statement int deleteCount = stmt.executeUpdate(sql); // deleteCount contains the number of deleted rows // Use a prepared statement to delete // Prepare a statement to delete a record sql = "DELETE FROM my_table WHERE col_string=?"; PreparedStatement pstmt = connection.prepareStatement(sql); // Set the value pstmt.setString(1, "a string"); deleteCount = pstmt.executeUpdate(); System.err.println(e.getMessage());

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.