List of usage examples for java.sql PreparedStatement setBytes
void setBytes(int parameterIndex, byte x[]) throws SQLException;
From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java
/** * JDBC?BLOB//from ww w . j a v a 2s .c om */ public void updateProcess(Process process) { super.updateProcess(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()); } } } }
From source file:dao.PblogMessageAddQuery.java
/** * This method is not called by spring./*from w ww . j a v a 2 s. c o m*/ * It adds a message to collabrum topic * @param conn the connection passed to this. * @param tid the thread id * @param mid the message id * @param message the message * @param topic the topic or the subject * @param ownerid - the id of the member who is posting the message. * @param blogid - the blogger's id on whose blog this message is being posted to. * @exception BaseDaoException */ public void run(Connection conn, String tid, String mid, String message, String topic, String ownerid, String blogId) throws BaseDaoException { // Long myownerid = new Long(ownerid); byte[] msg = { ' ' }; if (!RegexStrUtil.isNull(message)) { msg = message.getBytes(); } byte[] mytopic = { ' ' }; if (!RegexStrUtil.isNull(topic)) { mytopic = topic.getBytes(); } PreparedStatement query = null; logger.info("pblogmessage called"); try { String stmt = "insert into pblogmessages values (0, " + tid + ", " + mid + ", " + blogId + " ," + ownerid + ", CURRENT_TIMESTAMP(), ?, ?, 0, 0)"; query = conn.prepareStatement(stmt); query.setBytes(1, mytopic); query.setBytes(2, msg); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing pblogmessages addquery", e); } }
From source file:com.jagornet.dhcp.db.JdbcIdentityAssocDAO.java
public void create(final IdentityAssoc ia) { /**// w w w .ja v a2s . c o m * Note: see https://issues.apache.org/jira/browse/DERBY-3609 * "Formally, Derby does not support getGeneratedKeys since * DatabaseMetaData.supportsGetGeneratedKeys() returns false. * However, Statement.getGeneratedKeys() is partially implemented, * ... since it will only return a meaningful result when an single * row insert is done with INSERT...VALUES" * * Spring has thus provided a workaround as described here: * http://jira.springframework.org/browse/SPR-5306 */ GeneratedKeyHolder newKey = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement( "insert into identityassoc" + " (duid, iatype, iaid, state)" + " values (?, ?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS); ps.setBytes(1, ia.getDuid()); ps.setByte(2, ia.getIatype()); ps.setLong(3, ia.getIaid()); ps.setByte(4, ia.getState()); return ps; } }, newKey); Number newId = newKey.getKey(); if (newId != null) { ia.setId(newId.longValue()); } }
From source file:dao.DirectoryAddQuery.java
/** * This method is not called by spring./*from w w w .j a v a 2 s . c om*/ * * @param conn the connection passed to this. * @param dirname the directory name * @param keywords the keywords * @param catdsec the description of this category or directory * @param dirlink the link of this category * @param dirpath the path of this category * @param stateid the stateid of this category * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String dirname, String keywords, String dirdesc, String dirlink, String dirpath, String stateid, String ownerid) throws BaseDaoException { /* long dt = System.currentTimeMillis(); logger.debug("dt = " + dt); Date mydate = new Date(dt); logger.debug("mydate = " + mydate); */ byte[] mykeywords = null; if (!RegexStrUtil.isNull(keywords)) { mykeywords = keywords.getBytes(); } byte[] desc = null; if (!RegexStrUtil.isNull(dirdesc)) { desc = dirdesc.getBytes(); } byte[] path = null; if (!RegexStrUtil.isNull(dirpath)) { path = dirpath.getBytes(); } byte[] link = null; if (!RegexStrUtil.isNull(dirlink)) { link = dirlink.getBytes(); } byte[] mydirName = null; if (!RegexStrUtil.isNull(dirname)) { mydirName = dirname.getBytes(); } PreparedStatement query = null; String stmt = null; try { stmt = "insert into directory values (0, ?, " + ownerid + ", CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), ?, ?, stateid, ?, 0, ?)"; query = conn.prepareStatement(stmt); query.setBytes(1, mydirName); query.setBytes(2, mykeywords); query.setBytes(3, path); query.setBytes(4, link); query.setBytes(5, desc); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing directory addquery, query = " + stmt, e); } }
From source file:dao.DirectoryRenameQuery.java
/** * This method is not called by spring./*from w w w . ja v a 2 s . c om*/ * * @param conn the connection passed to this. * @param directoryid the directoryid id * @param dirname the directory name * @param keywords the keywords * @param dirdesc the category description * @exception BaseDaoException */ public void run(Connection conn, String directoryid, String dirname, String keywords, String desc) throws BaseDaoException { /* 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 dirname='" + dirname + "', 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, updating directory, query = " + stmt, e); } }
From source file:libepg.ts.aligner.Alligner2.java
public synchronized List<TsPacketParcel> getAllignedPackets() { JDBCAccessor ac = JDBCAccessor.getInstance(); try {/*w w w. j a v a 2 s. c o m*/ ac.connect(AboutDB.URL); Connection conn = ac.getConnection(); Statement stmt = conn.createStatement(); //? stmt.executeUpdate(CRATE_TABLE); //?PID?????? for (TsPacket tsp : this.packets) { // System.out.println(Integer.toHexString(tsp.getPid())); if (tsp.getPid() == this.getPid()) { PreparedStatement insertStatement = conn.prepareStatement(INSERT_SQL); insertStatement.setInt(1, tsp.getPid()); insertStatement.setInt(2, tsp.getContinuity_counter()); insertStatement.setInt(3, 0); insertStatement.setBytes(4, tsp.getData()); insertStatement.executeUpdate(); } } debug_dump_table(conn); // // // LinkedList<TsPacketParcel> temp = new LinkedList<>(); // for (TsPacket tsp : this.packets) { // // //??????0 // if (tsp.getAdaptation_field_control() == TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD) { // if (tsp.getContinuity_counter() == 0) { // temp.add(new TsPacketParcel(tsp, TsPacketParcel.MISSING_PACKET_FLAG.NOT_MISSING)); // } else if (LOG.isWarnEnabled()) { // LOG.warn("???0????????"); // LOG.warn(tsp); // } // } // // if (LOG.isTraceEnabled()) { // LOG.trace("????"); // } // if (temp.contains(tsp)) { // // } // } } catch (SQLException ex) { LOG.fatal(ex); } finally { ac.close(); } return null; }
From source file:org.sonar.server.db.migrations.v50.FeedFileSourcesTest.java
private void migrate_sources_with_scm_and_coverage_in(String columnName) throws Exception { db.prepareDbUnit(getClass(), "before.xml"); Connection connection = null; try {//from www .j av a2 s. c o m connection = db.openConnection(); connection .prepareStatement("insert into snapshot_sources " + "(snapshot_id, data, updated_at) " + "values " + "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')") .executeUpdate(); db.executeUpdateSql("insert into snapshot_sources " + "(snapshot_id, data, updated_at) " + "values " + "(7, '', '2014-10-31 16:44:02.000')"); PreparedStatement revisionStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(1, 6, ?)"); revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(Charsets.UTF_8)); revisionStmt.executeUpdate(); PreparedStatement authorStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(2, 6, ?)"); authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(Charsets.UTF_8)); authorStmt.executeUpdate(); PreparedStatement dateStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(3, 6, ?)"); dateStmt.setBytes(1, "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100" .getBytes(Charsets.UTF_8)); dateStmt.executeUpdate(); PreparedStatement utHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(4, 6, ?)"); utHitsStmt.setBytes(1, "1=1;3=0".getBytes(Charsets.UTF_8)); utHitsStmt.executeUpdate(); PreparedStatement utCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(5, 6, ?)"); utCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8)); utCondStmt.executeUpdate(); PreparedStatement utCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(6, 6, ?)"); utCoveredCondStmt.setBytes(1, "1=2".getBytes(Charsets.UTF_8)); utCoveredCondStmt.executeUpdate(); PreparedStatement itHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(7, 6, ?)"); itHitsStmt.setBytes(1, "1=2;3=0".getBytes(Charsets.UTF_8)); itHitsStmt.executeUpdate(); PreparedStatement itCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(8, 6, ?)"); itCondStmt.setBytes(1, "1=5".getBytes(Charsets.UTF_8)); itCondStmt.executeUpdate(); PreparedStatement itCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(9, 6, ?)"); itCoveredCondStmt.setBytes(1, "1=3".getBytes(Charsets.UTF_8)); itCoveredCondStmt.executeUpdate(); PreparedStatement overallHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(10, 6, ?)"); overallHitsStmt.setBytes(1, "1=3;3=0".getBytes(Charsets.UTF_8)); overallHitsStmt.executeUpdate(); PreparedStatement overallCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(11, 6, ?)"); overallCondStmt.setBytes(1, "1=6".getBytes(Charsets.UTF_8)); overallCondStmt.executeUpdate(); PreparedStatement overallCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(12, 6, ?)"); overallCoveredCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8)); overallCoveredCondStmt.executeUpdate(); PreparedStatement duplicationDataStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(13, 6, ?)"); duplicationDataStmt.setBytes(1, "<duplications><g><b s=\"1\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"2\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"3\" l=\"1\" r=\"MyProject:src/main/xoo/prj/AnotherFile.xoo\"/></g></duplications>" .getBytes(Charsets.UTF_8)); duplicationDataStmt.executeUpdate(); } finally { DbUtils.commitAndCloseQuietly(connection); } migration.execute(); db.assertDbUnit(getClass(), "after-with-scm.xml", "file_sources"); }
From source file:com.cedarsoftware.ncube.NCubeManager.java
/** * Update the notes associated to an NCube * * @return true if the update succeeds, false otherwise *//*w w w . j ava2 s .c o m*/ public static boolean updateNotes(Connection connection, String app, String name, String version, String notes) { validate(connection, app, version); validateCubeName(name); synchronized (cubeList) { PreparedStatement stmt = null; try { stmt = connection.prepareStatement( "UPDATE n_cube SET notes_bin = ?, update_dt = ? WHERE app_cd = ? AND n_cube_nm = ? AND version_no_cd = ?"); stmt.setBytes(1, notes == null ? null : notes.getBytes("UTF-8")); stmt.setDate(2, new java.sql.Date(System.currentTimeMillis())); stmt.setString(3, app); stmt.setString(4, name); stmt.setString(5, version); int count = stmt.executeUpdate(); if (count > 1) { throw new IllegalStateException("Only one (1) row's notes should be updated."); } if (count == 0) { throw new IllegalStateException( "No NCube matching app: " + app + ", name: " + name + ", version: " + version); } return true; } catch (IllegalStateException e) { throw e; } catch (Exception e) { throw new RuntimeException( "Unable to update notes for NCube: " + name + ", app: " + app + ", version: " + version, e); } finally { jdbcCleanup(stmt); } } }
From source file:dao.ColMessageAddQuery.java
/** * This method is not called by spring.// w w w .ja v a 2 s. c o m * It adds a message to collabrum topic * @param conn the connection passed to this. * @param tid the thread id * @param mid the message id * @param message the message * @param topic the topic or the subject * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String tid, String mid, String message, String topic, String ownerid) throws BaseDaoException { // need to assign a value to new byte as sql statement will not work byte[] msg = { ' ' }; if (!RegexStrUtil.isNull(message)) { msg = message.getBytes(); } byte[] mytopic = { ' ' }; if (!RegexStrUtil.isNull(topic)) { mytopic = topic.getBytes(); } PreparedStatement query = null; int rid = 0; try { String stmt = "insert into collmessages values (" + rid + ", " + tid + ", " + mid + ", " + ownerid + ", CURRENT_TIMESTAMP(), ?, ?, 0, 0)"; logger.info("stmt = " + stmt + " topic = " + topic + " message = " + message); query = conn.prepareStatement(stmt); query.setBytes(1, mytopic); query.setBytes(2, msg); query.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing collmessages addquery", e); throw new BaseDaoException("Error occured while executing collmessages addquery", e); } }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
public void deleteIaAddr(final IaAddress iaAddr) { getJdbcTemplate().update("delete from dhcplease" + " where ipaddress = ?", new PreparedStatementSetter() { @Override//w ww . j av a 2s . com public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaAddr.getIpAddress().getAddress()); } }); }