List of utility methods to do SQL Query
String | getSqlQuery(Statement statement, Object[] args) get Sql Query return statement instanceof PreparedStatement ? statement.toString() : Arrays.toString(args); |
PreparedStatement | getStatement(Connection con, String query, Object... bits) get Statement PreparedStatement stmt = con.prepareStatement(query); int i = 1; if (bits != null) { for (Object bit : bits) stmt.setObject(i++, bit); return stmt; |
ResultSet | query(Connection conn, String sql) query the specified SQL in database. PreparedStatement preparedStatement = conn.prepareStatement(sql);
return preparedStatement.executeQuery();
|
T | query(Connection conn, String sql, Object[] params, Class query PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); for (int i = 0; i < params.length; i++) { ps.setObject(i + 1, params[i]); ResultSet rs = ps.executeQuery(); Field[] fields = beanClass.getDeclaredFields(); ... |
List | query(Connection connection, String sql, boolean isClose, Object... params) query List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); PreparedStatement prepareStatement = null; try { sql = sql.replace("<", "<"); sql = sql.replace(">", ">"); sql = sql.replace("&", "&"); sql = sql.replace(""", "\""); sql = sql.replace("'", "'"); ... |
List | queryForList(Connection conn, String sql, int limit) query For List PreparedStatement ps = conn.prepareStatement(sql.trim());
ps.setMaxRows(limit);
ps.setFetchDirection(ResultSet.FETCH_FORWARD);
ResultSet rs = ps.executeQuery();
return toListMap(limit, rs);
|
List | queryObjectList(Connection con, String sql, Class query Object List List<T> lists = new ArrayList<T>(); Statement stmt = null; ResultSet rs = null; try { stmt = con.createStatement(); rs = stmt.executeQuery(sql); label: while (null != rs && rs.next()) { Constructor<?>[] constor = objClass.getConstructors(); ... |
int | queryProjectTicketIdFromTicketId(Connection db, int ticketId) query Project Ticket Id From Ticket Id int projectTicketId = -1; PreparedStatement pst = db.prepareStatement("SELECT key_count " + "FROM ticket " + "WHERE ticket_id = ? "); pst.setInt(1, ticketId); ResultSet rs = pst.executeQuery(); if (rs.next()) { projectTicketId = rs.getInt("key_count"); rs.close(); ... |
ResultSet | queryReturnRS(String sql) query Return RS if (null == conn) { return null; try { preStatement = conn.prepareStatement(sql); rs = preStatement.executeQuery(); } catch (SQLException e) { e.printStackTrace(); ... |
int | runQuery(Connection con, String query) to run an update query such as update, delete PreparedStatement st = con.prepareStatement(query);
return st.executeUpdate();
|