/**
 * Execute query. Mostly, it is for "select" query.
 * @param stat the Statement object
 * @param query the query that is intended to execute
 * @return the result of the execution of the query
 */
public static java.sql.ResultSet sqlExecuteQuery(java.sql.Statement stat, String query) {
	java.sql.ResultSet rs = null;
	try {
		rs = stat.executeQuery(query);
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
	return rs;
}
 
public static java.sql.ResultSet sqlExecuteQuery(java.sql.PreparedStatement pre) {
	java.sql.ResultSet rs = null;
	try {
		rs = pre.executeQuery();
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
	return rs;
}
 
public static java.sql.ResultSet sqlExecuteQuery(java.sql.PreparedStatement pre, int... para) {
	java.sql.ResultSet rs = null;
	try {
		for (int i = 0; i < para.length; i++) {
			pre.setInt(i + 1, para[i]);
		}
		rs = pre.executeQuery();
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
	return rs;
}
 
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

Sees the importance of signal filtering in medical imaging

Dhruv Lamba, BSEE2010