List of utility methods to do SQL PreparedStatement
PreparedStatement | prepareStatement(String parameterizedSQL, List> values, Connection conn) prepare Statement PreparedStatement pstmt = conn.prepareStatement(parameterizedSQL);
populateStatement(pstmt, values);
return pstmt;
|
PreparedStatement | prepareStatement(String parameterizedSQL, List prepare Statement PreparedStatement pstmt = conn.prepareStatement(parameterizedSQL); for (int i = 0; values != null && i < values.size(); i++) { try { String val = (String) values.get(i); if (val != null && val.equals("NULL")) pstmt.setNull(i + 1, Types.NULL); else pstmt.setObject(i + 1, values.get(i)); ... |
PreparedStatement | prepareStatement(String query) Prepares an SQL query statement to the database using the active database connection. return connection.prepareStatement(query);
|
PreparedStatement | prepareStatementForwardReadOnly(Connection conn, String name, String sql) prepare statements for this connection PreparedStatement ps = null; try { ps = prepareForwardReadOnly(conn, sql); } finally { if (ps == null) { System.err.println("Warning: couldn't initialize " + name + " from " + sql); return ps; |
void | putArgsToStatement(PreparedStatement stmt, List put Args To Statement if (args != null) { for (int i = 0; i < args.size(); i++) { stmt.setObject(i + 1, args.get(i)); |
ResultSet | query(List Don't forget: After execute query, we need to close resultset, prepared statement and connection in persistence layer ResultSet result = null; try { Iterator<String> paramIter = paramList.iterator(); int i = 1; while (paramIter.hasNext()) { String eachParam = paramIter.next(); pstmt.setString(i, eachParam); i++; ... |
long | runInsertLong(PreparedStatement s) runInsertLong is a database insert helper function, it runs an insert and returns a Long value based on the result of the query - Statements must return a value to be used with this function long rval = -1; try { ResultSet rs = s.executeQuery(); if (rs.next()) { rval = rs.getLong(1); System.out.println("SQL Insert rval: " + rval); rs.close(); ... |
void | saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue, String userId, PreparedStatement ps) Private helper method to save a resource info record. int index = 1; ps.setLong(index++, resourceId); ps.setLong(index++, propertyId); ps.setString(index++, propertyValue); ps.setString(index++, userId); ps.setString(index++, userId); int nr = ps.executeUpdate(); if (nr != 1) { ... |
void | setByte(PreparedStatement statement, int index, Byte value) Sets a SQL parameter of type byte using a prepared SQL statement, an index and a value. if (statement != null) { if (value == null) { statement.setNull(index, Types.TINYINT); } else { statement.setByte(index, value.byteValue()); |
void | setBytes(PreparedStatement pstmt, int index, byte[] bytes) set Bytes if (bytes != null) { pstmt.setBytes(index, bytes); } else { pstmt.setNull(index, Types.BINARY); |