List of usage examples for java.sql PreparedStatement setBytes
void setBytes(int parameterIndex, byte x[]) throws SQLException;
From source file:org.snaker.engine.access.jdbc.JdbcAccess.java
/** * JDBC?BLOB// ww w .j a v a2s .co m */ public void updateProcess(Process process) { super.updateProcess(process); if (process.getBytes() != null) { Connection conn = null; PreparedStatement pstmt = null; try { conn = getConnection(); pstmt = conn.prepareStatement(PROCESS_UPDATE_BLOB); pstmt.setBytes(1, process.getBytes()); pstmt.setString(2, process.getId()); pstmt.execute(); } catch (Exception e) { throw new SnakerException(e.getMessage(), e.getCause()); } finally { try { JdbcHelper.close(pstmt); } catch (SQLException e) { throw new SnakerException(e.getMessage(), e.getCause()); } } } }
From source file:dao.DirectoryUpdateQuery.java
/** * This method is not called by spring.//w ww.j a v a 2 s.c o m * * @param conn the connection passed to this. * @param directoryid the category id * @param dirname the directory name * @param keywords the keywords * @param parentname the parent of this category or directory * @param stateid the state id * @param catdesc the category description * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String directoryid, String keywords, String desc) throws BaseDaoException { // long dt = new java.util.Date().getTime(); /* long dt = System.currentTimeMillis(); Date mydate = new Date(dt); */ byte[] mydesc = { ' ' }; if (!RegexStrUtil.isNull(desc)) { mydesc = desc.getBytes(); } byte[] mykeywords = { ' ' }; if (!RegexStrUtil.isNull(keywords)) { mykeywords = keywords.getBytes(); } PreparedStatement query = null; String stmt = null; try { stmt = "update directory set keywords=?, dirdesc=?, accessdate=CURRENT_TIMESTAMP() where directoryid=" + directoryid + ""; query = conn.prepareStatement(stmt); query.setBytes(1, mykeywords); query.setBytes(2, mydesc); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured executing directory update query + query = " + stmt, e); } }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public List<InetAddress> findExistingIPs(final InetAddress startAddr, final InetAddress endAddr) { return getJdbcTemplate().query("select ipaddress from iaaddress" + " where ipaddress >= ? and ipaddress <= ?" + " order by ipaddress", new PreparedStatementSetter() { @Override//from w w w .j a v a2 s .c om public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, startAddr.getAddress()); ps.setBytes(2, endAddr.getAddress()); } }, new RowMapper<InetAddress>() { @Override public InetAddress mapRow(ResultSet rs, int rowNum) throws SQLException { InetAddress inetAddr = null; try { inetAddr = InetAddress.getByAddress(rs.getBytes("ipaddress")); } catch (UnknownHostException e) { // re-throw as SQLException throw new SQLException("Unable to map ipaddress", e); } return inetAddr; } }); }
From source file:org.sleuthkit.autopsy.casemodule.SingleUserCaseConverter.java
/** * Place a NULL inside a prepared statement if needed, otherwise, place the * byte array that was in the ResultSet. * * @param pst the prepared statement * @param rs the ResultSet to work with * @param rsIndex index for the result set * @param psIndex index for the prepared statement * * @throws SQLException/*from w ww .j a v a2s . c o m*/ */ private static void populateNullableByteArray(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex) throws SQLException { byte[] nullableBytes = rs.getBytes(rsIndex); if (rs.wasNull()) { pst.setNull(psIndex, java.sql.Types.NULL); } else { pst.setBytes(psIndex, nullableBytes); } }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public List<InetAddress> findExistingIPs(final InetAddress startAddr, final InetAddress endAddr) { return getJdbcTemplate().query("select prefixaddress from iaprefix" + " where prefixaddress >= ? and prefixaddress <= ?" + " order by prefixaddress", new PreparedStatementSetter() { @Override//from w w w. j a v a2 s .c om public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, startAddr.getAddress()); ps.setBytes(2, endAddr.getAddress()); } }, new RowMapper<InetAddress>() { @Override public InetAddress mapRow(ResultSet rs, int rowNum) throws SQLException { InetAddress inetAddr = null; try { inetAddr = InetAddress.getByAddress(rs.getBytes("prefixaddress")); } catch (UnknownHostException e) { // re-throw as SQLException throw new SQLException("Unable to map prefixaddress", e); } return inetAddr; } }); }
From source file:org.sonar.server.computation.db.AnalysisReportDao.java
private void setData(PreparedStatement ps, int parameterIndex, @Nullable InputStream reportDataStream) throws IOException, SQLException { if (reportDataStream == null) { ps.setBytes(parameterIndex, null); } else {//from w w w. j av a 2 s .co m ps.setBytes(parameterIndex, ByteStreams.toByteArray(reportDataStream)); } }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public void update(final IaAddress iaAddr) { String updateQuery = "update iaaddress" + " set ipaddress=?," + " starttime=?," + " preferredendtime=?," + " validendtime=?," + " state=?," + " identityassoc_id=?" + " where id=?"; getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() { @Override/*from w ww. j a v a2 s. co m*/ public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaAddr.getIpAddress().getAddress()); Date start = iaAddr.getStartTime(); if (start != null) { java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime()); ps.setTimestamp(2, sts, Util.GMT_CALENDAR); } else { ps.setNull(2, java.sql.Types.TIMESTAMP); } Date preferred = iaAddr.getPreferredEndTime(); if (preferred != null) { java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime()); ps.setTimestamp(3, pts, Util.GMT_CALENDAR); } else { ps.setNull(3, java.sql.Types.TIMESTAMP); } Date valid = iaAddr.getValidEndTime(); if (valid != null) { java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime()); ps.setTimestamp(4, vts, Util.GMT_CALENDAR); } else { ps.setNull(4, java.sql.Types.TIMESTAMP); } ps.setByte(5, iaAddr.getState()); ps.setLong(6, iaAddr.getIdentityAssocId()); ps.setLong(7, iaAddr.getId()); } }); }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public void update(final IaPrefix iaPrefix) { String updateQuery = "update iaprefix" + " set prefixaddress=?," + " prefixlength=?," + " starttime=?," + " preferredendtime=?," + " validendtime=?," + " state=?," + " identityassoc_id=?" + " where id=?"; getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() { @Override//from ww w . j ava2 s . c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaPrefix.getIpAddress().getAddress()); ps.setInt(2, iaPrefix.getPrefixLength()); Date start = iaPrefix.getStartTime(); if (start != null) { java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime()); ps.setTimestamp(3, sts, Util.GMT_CALENDAR); } else { ps.setNull(3, java.sql.Types.TIMESTAMP); } Date preferred = iaPrefix.getPreferredEndTime(); if (preferred != null) { java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime()); ps.setTimestamp(4, pts, Util.GMT_CALENDAR); } else { ps.setNull(4, java.sql.Types.TIMESTAMP); } Date valid = iaPrefix.getValidEndTime(); if (valid != null) { java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime()); ps.setTimestamp(5, vts, Util.GMT_CALENDAR); } else { ps.setNull(5, java.sql.Types.TIMESTAMP); } ps.setByte(6, iaPrefix.getState()); ps.setLong(7, iaPrefix.getIdentityAssocId()); ps.setLong(8, iaPrefix.getId()); } }); }
From source file:dao.DirWebsiteUpdateQuery.java
/** * This method is not called by spring./* www . j ava2s .c om*/ * * @param conn the connection passed to this. * @param url the url * @param title the title * @param entryid the entry id * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String url, String title, String entryid, String ownerid) throws BaseDaoException { // long dt = new java.util.Date().getTime(); /* long dt = System.currentTimeMillis(); Date mydate = new Date(dt); */ byte[] myUrl = { ' ' }; if (!RegexStrUtil.isNull(url)) { myUrl = url.getBytes(); } byte[] myTitle = { ' ' }; if (!RegexStrUtil.isNull(title)) { myTitle = title.getBytes(); } PreparedStatement query = null; String stmt = null; try { stmt = "update dirwebsites set url=?, title=?, webdate=CURRENT_TIMESTAMP() where entryid=" + entryid + " and ownerid=" + ownerid + ""; query = conn.prepareStatement(stmt); query.setBytes(1, myUrl); query.setBytes(2, myTitle); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing directory update query + query = " + stmt, e); } }
From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java
/** * JDBC?BLOB//from w w w . j ava 2 s . c o m */ public void saveProcess(Process process) { super.saveProcess(process); SqlSession sqlSession = getSession(); if (process.getBytes() != null) { Connection conn = null; PreparedStatement pstmt = null; try { conn = sqlSession.getConnection(); pstmt = conn.prepareStatement(PROCESS_UPDATE_BLOB); pstmt.setBytes(1, process.getBytes()); pstmt.setString(2, process.getId()); pstmt.execute(); } catch (Exception e) { throw new SnakerException(e.getMessage(), e.getCause()); } finally { try { JdbcHelper.close(pstmt); SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory()); } catch (SQLException e) { throw new SnakerException(e.getMessage(), e.getCause()); } } } }