diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java index 81e521b5..e3f533bc 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java @@ -1,5 +1,5 @@ // -// $Id: JDBCUtil.java,v 1.2 2001/08/11 22:43:28 mdb Exp $ +// $Id: JDBCUtil.java,v 1.3 2002/02/01 18:33:16 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -22,6 +22,8 @@ package com.samskivert.jdbc; import java.sql.*; +import com.samskivert.io.PersistenceException; + /** * A repository for JDBC related utility functions. */ @@ -50,4 +52,22 @@ public class JDBCUtil conn.close(); } } + + /** + * Calls stmt.executeUpdate() on the supplied statement, + * checking to see that it returns the expected update count and + * throwing a persistence exception if it does not. + */ + public static void checkedUpdate ( + PreparedStatement stmt, int expectedCount) + throws SQLException, PersistenceException + { + int modified = stmt.executeUpdate(); + if (modified != expectedCount) { + String err = "Statement did not modify expected number of rows " + + "[stmt=" + stmt + ", expected=" + expectedCount + + ", modified=" + modified + "]"; + throw new PersistenceException(err); + } + } }