Revision as of 17:40, 22 March 2011 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/**
 * Update database.
 * @param stat the Statement object
 * @param query the query that is intended to execute
 * @return the number of updated rows
 */
public static int sqlUpdateQuery(java.sql.Statement stat, String query) {
	int result = 0;
	try {
		result = stat.executeUpdate(query);
	} catch (java.sql.SQLException ex) {
		// Ignoring the exception like below line is not good.
		// It will cause severe unnoticible problems.
//			return 0;
		// Do not add ";" at the end of the query.
		// It will cause the error (ORA-00911: invalid character) if you use Oracle.
		Ts.printErr(ex);
	}
	return result;
}
 
 
public static void printErr(java.sql.SQLException ex) {
	System.out.println("SQL State: " + ex.getSQLState());
	System.out.println("Error Code: " + ex.getErrorCode());
	Ts.printErr((java.lang.Exception) ex);
}
 
public static void printErr(java.lang.Exception ex) {
	ex.printStackTrace();
	System.exit(-1);
}


Back to JavaHowTo

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang