(New page: <source lang="java"> public static java.sql.ResultSet sqlExecuteQuery(java.sql.PreparedStatement pre) { java.sql.ResultSet rs = null; try { rs = pre.executeQuery(); } catch (java.sql...) |
|||
Line 1: | Line 1: | ||
<source lang="java"> | <source lang="java"> | ||
+ | |||
+ | /** | ||
+ | * 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) { | public static java.sql.ResultSet sqlExecuteQuery(java.sql.PreparedStatement pre) { |
Latest revision as of 16:39, 22 March 2011
/** * 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); }