示例#1
0
文件: DBTools.java 项目: perkyliu/jd
 public static Map<String, String> queryToMap(String dataSourceName, String sql, Object[] params) {
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     conn = getConnection(dataSourceName);
     stmt = conn.prepareStatement(sql);
     if (null != params && params.length > 0) {
       setStatementParameters(stmt, params);
     }
     rs = stmt.executeQuery();
     if (rs.next()) {
       Map<String, String> result = new HashMap<String, String>();
       ResultSetMetaData rsmd = rs.getMetaData();
       int columnCount = rsmd.getColumnCount();
       for (int i = 1; i <= columnCount; ++i) {
         result.put(rsmd.getColumnName(i).toUpperCase(), rs.getString(i));
       }
       return result;
     }
   } catch (SQLException sqlex) {
     logger.warning(sqlex.getMessage());
     throw new RuntimeException(sqlex);
   } finally {
     closeDB(conn, stmt, rs);
   }
   return null;
 }
示例#2
0
文件: DBTools.java 项目: perkyliu/jd
 public static ResultSet executeQuery(String dataSourceName, String sql) throws SQLException {
   Connection conn = getConnection(dataSourceName);
   Statement stmt = null;
   ResultSet rs = null;
   try {
     stmt = conn.createStatement();
     rs = stmt.executeQuery(sql);
   } catch (SQLException e) {
     throw e;
   } finally {
     closeDB(conn, stmt, null);
   }
   return rs;
 }
示例#3
0
文件: DBTools.java 项目: perkyliu/jd
 public static int executeUpdate(String dataSourceName, String sql) throws SQLException {
   int resultCount = 0;
   Connection conn = getConnection(dataSourceName);
   Statement stmt = null;
   try {
     stmt = conn.createStatement();
     resultCount = stmt.executeUpdate(sql);
   } catch (SQLException e) {
     throw e;
   } finally {
     closeDB(conn, stmt, null);
   }
   return resultCount;
 }
示例#4
0
文件: DBTools.java 项目: perkyliu/jd
 public static List<Object[]> queryToObjArrList(
     String dataSourceName, String sql, Object[] params) {
   Connection conn = null;
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     conn = getConnection(dataSourceName);
     stmt = conn.prepareStatement(sql);
     if (null != params && params.length > 0) {
       setStatementParameters(stmt, params);
     }
     rs = stmt.executeQuery();
     return getResultObjArrList(rs);
   } catch (SQLException sqlex) {
     logger.warning(sqlex.getMessage());
     throw new RuntimeException(sqlex);
   } finally {
     closeDB(conn, stmt, rs);
   }
 }