List of utility methods to do SQL PreparedStatement
PreparedStatement | fillStatement(PreparedStatement ps, Object... params) Fill a raw PreparedStatement to make it executable. try { for (int i = 0; i < params.length; i++) { ps.setObject(i + 1, params[i]); } catch (SQLException e) { e.printStackTrace(); return ps; ... |
void | fillStatement(PreparedStatement stmt, Object[] params) Fill the PreparedStatement replacement parameters with the given objects.
if (params == null) { return; for (int i = 0; i < params.length; i++) { if (params[i] != null) { stmt.setObject(i + 1, params[i]); } else { stmt.setNull(i + 1, Types.VARCHAR); ... |
String | getFileContent(final File file) Fully reads the given file content and returns it (to be used be small files only). FileInputStream fis = null; String content = null; try { fis = new FileInputStream(file); final byte arrBytes[] = new byte[fis.available()]; fis.read(arrBytes); content = new String(arrBytes); } finally { ... |
Object | getGeneratedKey(PreparedStatement ps) get Generated Key Object key = null; ResultSet rs = null; try { rs = ps.getGeneratedKeys(); if (rs.next()) { key = rs.getObject(1); } catch (SQLException e) { ... |
int | getGenerateKey(PreparedStatement stmt) get Generate Key int key = 0; ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { key = rs.getInt(1); return key; |
long | getIdentity(PreparedStatement stat) Returns the value for IDENTITY column returned by the last execution of the given statement. ResultSet rs = stat.getGeneratedKeys();
rs.next();
return rs.getBigDecimal(1).longValue();
|
Integer | getLastId(PreparedStatement s) get Last Id if (s == null) return null; ResultSet rs = s.getGeneratedKeys(); if (!rs.next()) return null; return rs.getInt(1); |
PreparedStatement | getLimitedBatchSizePreparedStatement(PreparedStatement pstmt, int maxBatchSize) This method wraps the PreparedStatement given as argument into a delegate object that calls the executeBatch method every maxBatchSize th time a batch is added to the statement with the addBatch method.
return null;
|
PreparedStatement | getNewPreparedStatement(String format) get New Prepared Statement try { if (connection == null) connection = getNewConnection(); PreparedStatement s = connection.prepareStatement(format); return s; } catch (SQLException e) { return null; ... |
PreparedStatement | getPreparedStatement(Connection conn, String sql) get Prepared Statement try { return conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); } catch (SQLException e) { e.printStackTrace(); return null; |