(New page: <source lang="java"> →* * Return the string array for specific column. First colum is 1 rather than 0. * @param rs * @param colNum start from one * @return: public static String[]...) |
|||
Line 21: | Line 21: | ||
return result; | return result; | ||
} | } | ||
+ | |||
/** | /** | ||
* Return the integer array for specific column. | * Return the integer array for specific column. | ||
Line 41: | Line 42: | ||
return result; | return result; | ||
} | } | ||
+ | |||
public static double[] sqlGetColDouble(java.sql.ResultSet rs, int colNum) { | public static double[] sqlGetColDouble(java.sql.ResultSet rs, int colNum) { | ||
int len = Ts.sqlResultSetLength(rs); | int len = Ts.sqlResultSetLength(rs); | ||
Line 55: | Line 57: | ||
return result; | return result; | ||
} | } | ||
+ | |||
/** | /** | ||
* This method is similar to sqlGetColDouble but it does not use sqlResultSetLength method. | * This method is similar to sqlGetColDouble but it does not use sqlResultSetLength method. |
Latest revision as of 16:43, 22 March 2011
/** * Return the string array for specific column. First colum is 1 rather than 0. * @param rs * @param colNum start from one * @return */ public static String[] sqlGetColStr(java.sql.ResultSet rs, int colNum) { int len = Ts.sqlResultSetLength(rs); String[] result = new String[len]; try { for (int i = 0; i < len; i++) { rs.next(); result[i] = rs.getString(colNum); } rs.beforeFirst(); } catch (java.sql.SQLException ex) { Ts.printErr(ex); } return result; } /** * Return the integer array for specific column. * @param rs * @param colNum start from one * @return */ public static int[] sqlGetColInt(java.sql.ResultSet rs, int colNum) { int len = Ts.sqlResultSetLength(rs); int[] result = new int[len]; try { for (int i = 0; i < len; i++) { rs.next(); result[i] = rs.getInt(colNum); } rs.beforeFirst(); } catch (java.sql.SQLException ex) { Ts.printErr(ex); } return result; } public static double[] sqlGetColDouble(java.sql.ResultSet rs, int colNum) { int len = Ts.sqlResultSetLength(rs); double[] result = new double[len]; try { for (int i = 0; i < len; i++) { rs.next(); result[i] = rs.getDouble(colNum); } rs.beforeFirst(); } catch (java.sql.SQLException ex) { Ts.printErr(ex); } return result; } /** * This method is similar to sqlGetColDouble but it does not use sqlResultSetLength method. * @param rs * @param colNum * @return */ public static double[] sqlGetColDouble2(java.sql.ResultSet rs, int colNum) { java.util.List<Double> list = new java.util.LinkedList<Double>(); try { while (rs.next()) { list.add(rs.getDouble(colNum)); } rs.beforeFirst(); } catch (java.sql.SQLException ex) { Ts.printErr(ex); } return Ts.listToArrayDouble(list); } 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); }