![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e262. Deleting a Row from a Database Tabletry { // 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());
© 2002 Addison-Wesley. |