Revision as of 16:39, 22 March 2011 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
public static int sqlExecuteQueryOneInt(java.sql.Statement stat, String query) {
	java.sql.ResultSet rs = null;
	int result = 0;
	try {
		rs = stat.executeQuery(query);
		if (rs.next()) {
			result = rs.getInt(1);
		} else {
			Ts.printErr("There is no result.");
		}
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
	return result;
}
 
public static double sqlExecuteQueryOneDouble(java.sql.Statement stat, String query) {
	java.sql.ResultSet rs = null;
	double result = 0;
	try {
		rs = stat.executeQuery(query);
		if (rs.next()) {
			result = rs.getDouble(1);
		} else {
			Ts.printErr("There is no result.");
		}
	} catch (java.sql.SQLException ex) {
		Ts.printErr(ex);
	}
	return result;
}
 
public static String sqlExecuteQueryOneString(java.sql.Statement stat, String query) {
	java.sql.ResultSet rs = null;
	String result = null;
	try {
		rs = stat.executeQuery(query);
		if (rs.next()) {
			result = rs.getString(1);
		} else {
			Ts.printErr("There is no result.");
		}
	} catch (java.sql.SQLException ex) {
		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

Sees the importance of signal filtering in medical imaging

Dhruv Lamba, BSEE2010