Added checkedUpdate() which is useful for ensuring that an insertion
modifies the expected number of rows. git-svn-id: https://samskivert.googlecode.com/svn/trunk@552 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -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 <code>stmt.executeUpdate()</code> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user