List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:migration.ProjektMigration.java
/** * Creates the exemplar./*from w w w . j av a2s. c om*/ * * @param con * the con */ public void createExemplar(final Connection con) { String load_sql; Statement load_stmt; ResultSet load_rs; String store_sql; PreparedStatement store_prepstmt; final ResultSet store_rs; try { load_sql = "select Besteller, Exemplar, Sigel, Titelnummer AS Journal, Lieferant, Printan, Beteiligung, Form, Zugangsart, " + "Status, Bestellnummer, Kundennummer, AboNummer, Privatabo, ExKommentar, PrintexBayern, " + "AbbestZum, Abbestellung, UmbestZum, Umbestellung from Exemplartabelle "; load_stmt = this.leg_con.createStatement(); store_sql = "insert into exemplar (abbestZum, abbestellung, abonummer, bestellnummer, beteiligung, " + "exKommentar, form, kundennummer, printexBayern, privatabo, status, umbestZum, umbestellung, zugangsart, " + "besteller_sigelId, eigentuemer_sigelId, journal_id, lieferant_id, zustaendigeBib_sigelId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl. // brauchen // wir // was // in // Richtung: // Statement.RETURN_GENERATED_KEYS final int laenge = this.help.sqlGetLength(con, load_sql); this.exemplare = new int[laenge]; // logger.info("Lese von Besteller"); load_stmt.execute(load_sql); load_rs = load_stmt.getResultSet(); // logger.info("Schreibe nach Besteller"); for (int i = 0; i < laenge; i++) { // System.err.println("geht doch!"); load_rs.next(); this.exemplare[i] = load_rs.getInt("Exemplar"); store_prepstmt.setDate(1, load_rs.getDate("AbbestZum")); store_prepstmt.setString(2, load_rs.getString("Abbestellung")); store_prepstmt.setString(3, load_rs.getString("AboNummer")); store_prepstmt.setString(4, load_rs.getString("Bestellnummer")); store_prepstmt.setString(5, load_rs.getString("Beteiligung")); store_prepstmt.setString(6, load_rs.getString("exKommentar")); store_prepstmt.setString(7, load_rs.getString("Form")); store_prepstmt.setString(8, load_rs.getString("Kundennummer")); store_prepstmt.setString(9, load_rs.getString("PrintexBayern")); store_prepstmt.setBoolean(10, load_rs.getBoolean("privatabo")); store_prepstmt.setString(11, load_rs.getString("Status")); store_prepstmt.setDate(12, load_rs.getDate("UmbestZum")); store_prepstmt.setString(13, load_rs.getString("Umbestellung")); store_prepstmt.setString(14, load_rs.getString("Zugangsart")); final String besteller = load_rs.getString("Besteller"); final int bestellerID_neu = this.help.getIdFromStringArray(this.bestellers, besteller); int sigelID = 0; if (bestellerID_neu != 0) { sigelID = this.bestellers_sigels[bestellerID_neu - 1]; } if (sigelID != 0) { store_prepstmt.setLong(15, sigelID); } else { store_prepstmt.setNull(15, java.sql.Types.BIGINT); } final String print = load_rs.getString("Printan"); // System.err.println("print: "+print+" getID: "+help.getIdFromStringArray(help.getSigel(), // print)); if (this.help.getIdFromStringArray(this.help.getSigel(), print) != 0) { store_prepstmt.setLong(16, (this.help.getIdFromStringArray(this.help.getSigel(), print))); } else { store_prepstmt.setNull(16, java.sql.Types.BIGINT); } final int j = load_rs.getInt("Journal"); // System.err.println("journal: "+j+" getID: "+help.getIdFromIntArray(help.getJournals(), // j)); if (this.help.getIdFromIntArray(this.help.getJournals(), j) != 0) { store_prepstmt.setLong(17, this.help.getIdFromIntArray(this.help.getJournals(), j)); } else { store_prepstmt.setNull(17, java.sql.Types.BIGINT); } final String lief = load_rs.getString("Lieferant"); // System.err.println("lieferant: "+ lief + // " ist "+help.getIdFromStringArray(help.getInstitutionen(), // lief)); if (this.help.getIdFromStringArray(this.help.getInstitutionen(), lief) != 0) { store_prepstmt.setLong(18, this.help.getIdFromStringArray(this.help.getInstitutionen(), lief)); } else { store_prepstmt.setNull(18, java.sql.Types.BIGINT); } final String s = load_rs.getString("Sigel"); // System.err.println("zustndige Bib: "+ s + // " ist "+help.getIdFromStringArray(help.getSigel(), s)); if (this.help.getIdFromStringArray(this.help.getSigel(), s) != 0) { store_prepstmt.setLong(19, this.help.getIdFromStringArray(this.help.getSigel(), s)); } else { store_prepstmt.setNull(19, java.sql.Types.BIGINT); } store_prepstmt.executeUpdate(); } } catch (final SQLException e) { e.printStackTrace(); // To change body of catch statement use File | // Settings | File Templates. } // insert into Interesse (besteller_bestellerId, interesse, journal_id) // values (?, ?, ?) // insert into Nutzung (journal_id, nutzungsjahr, rechnungsbetrag, // zeitraum, zugriffe) values (?, ?, ?, ?, ?) // insert into Rechnung (betrag, bezugsform, bezugsjahr, // exemplar_exemplarId, sigel_sigelId) values (?, ?, ?, ?, ?) }
From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java
@Override public void insertMessage(Message message) { logger.debug(message.getChannelId() + "/" + message.getMessageId() + ": inserting message"); try {//from w w w .j ava 2 s . com PreparedStatement statement = prepareStatement("insertMessage", message.getChannelId()); statement.setLong(1, message.getMessageId()); statement.setString(2, message.getServerId()); statement.setTimestamp(3, new Timestamp(message.getReceivedDate().getTimeInMillis())); statement.setBoolean(4, message.isProcessed()); Long originalId = message.getOriginalId(); if (originalId != null) { statement.setLong(5, originalId); } else { statement.setNull(5, Types.BIGINT); } Long importId = message.getImportId(); if (importId != null) { statement.setLong(6, importId); } else { statement.setNull(6, Types.BIGINT); } String importChannelId = message.getImportChannelId(); if (importChannelId != null) { statement.setString(7, message.getImportChannelId()); } else { statement.setNull(7, Types.VARCHAR); } statement.executeUpdate(); } catch (SQLException e) { throw new DonkeyDaoException(e); } }
From source file:org.apache.sqoop.repository.derby.DerbyRepositoryHandler.java
/** * Create an HDFS connection ( used only in version 2). * Intended to be used when moving HDFS connector out of the sqoop driver * to its own connector./*from w ww.j av a 2 s.c o m*/ * * NOTE: Should be used only in the upgrade path! */ @Deprecated private Long createHdfsConnection(Connection conn, Long connectorId) { if (LOG.isTraceEnabled()) { LOG.trace("Creating HDFS link."); } PreparedStatement stmt = null; int result; try { stmt = conn.prepareStatement(STMT_INSERT_CONNECTION, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, CONNECTOR_HDFS); stmt.setLong(2, connectorId); stmt.setBoolean(3, true); stmt.setNull(4, Types.VARCHAR); stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis())); stmt.setNull(6, Types.VARCHAR); stmt.setTimestamp(7, new Timestamp(System.currentTimeMillis())); result = stmt.executeUpdate(); if (result != 1) { throw new SqoopException(DerbyRepoError.DERBYREPO_0003, Integer.toString(result)); } ResultSet rsetConnectionId = stmt.getGeneratedKeys(); if (!rsetConnectionId.next()) { throw new SqoopException(DerbyRepoError.DERBYREPO_0004); } if (LOG.isTraceEnabled()) { LOG.trace("Created HDFS connection."); } return rsetConnectionId.getLong(1); } catch (SQLException ex) { throw new SqoopException(DerbyRepoError.DERBYREPO_0005, ex); } finally { closeStatements(stmt); } }
From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java
public void storeContent(String channelId, long messageId, int metaDataId, ContentType contentType, String content, String dataType, boolean encrypted) { try {/* w w w. j a v a2 s . c o m*/ // Only encrypt if the content is not already encrypted if (encryptData && encryptor != null && !encrypted) { content = encryptor.encrypt(content); encrypted = true; } PreparedStatement statement = prepareStatement("storeMessageContent", channelId); if (content == null) { statement.setNull(1, Types.LONGVARCHAR); } else { statement.setString(1, content); } statement.setString(2, dataType); statement.setBoolean(3, encrypted); statement.setInt(4, metaDataId); statement.setLong(5, messageId); statement.setInt(6, contentType.getContentTypeCode()); int rowCount = statement.executeUpdate(); statement.clearParameters(); if (rowCount == 0) { // This is the same code as insertContent, without going through the encryption process again logger.debug(channelId + "/" + messageId + "/" + metaDataId + ": updating message content (" + contentType.toString() + ")"); statement = prepareStatement("insertMessageContent", channelId); statement.setInt(1, metaDataId); statement.setLong(2, messageId); statement.setInt(3, contentType.getContentTypeCode()); statement.setString(4, content); statement.setString(5, dataType); statement.setBoolean(6, encrypted); statement.executeUpdate(); statement.clearParameters(); } } catch (SQLException e) { throw new DonkeyDaoException(e); } }
From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java
private void insertContent(String channelId, long messageId, int metaDataId, ContentType contentType, String content, String dataType, boolean encrypted) { try {/*from www .j a v a2 s . c o m*/ // Only encrypt if the content is not already encrypted if (encryptData && encryptor != null && !encrypted) { content = encryptor.encrypt(content); encrypted = true; } PreparedStatement statement = prepareStatement("insertMessageContent", channelId); statement.setInt(1, metaDataId); statement.setLong(2, messageId); statement.setInt(3, contentType.getContentTypeCode()); statement.setString(4, content); statement.setString(5, dataType); statement.setBoolean(6, encrypted); statement.executeUpdate(); statement.clearParameters(); } catch (SQLException e) { throw new DonkeyDaoException(e); } }
From source file:org.apache.sqoop.repository.derby.DerbyRepositoryHandler.java
/** * {@inheritDoc}/*from ww w . j a v a 2 s .c om*/ */ @Override public void createLink(MLink link, Connection conn) { PreparedStatement stmt = null; int result; try { stmt = conn.prepareStatement(STMT_INSERT_LINK, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, link.getName()); stmt.setLong(2, link.getConnectorId()); stmt.setBoolean(3, link.getEnabled()); stmt.setString(4, link.getCreationUser()); stmt.setTimestamp(5, new Timestamp(link.getCreationDate().getTime())); stmt.setString(6, link.getLastUpdateUser()); stmt.setTimestamp(7, new Timestamp(link.getLastUpdateDate().getTime())); result = stmt.executeUpdate(); if (result != 1) { throw new SqoopException(DerbyRepoError.DERBYREPO_0012, Integer.toString(result)); } ResultSet rsetConnectionId = stmt.getGeneratedKeys(); if (!rsetConnectionId.next()) { throw new SqoopException(DerbyRepoError.DERBYREPO_0013); } long connectionId = rsetConnectionId.getLong(1); createInputValues(STMT_INSERT_LINK_INPUT, connectionId, link.getConnectorLinkConfig().getConfigs(), conn); link.setPersistenceId(connectionId); } catch (SQLException ex) { logException(ex, link); throw new SqoopException(DerbyRepoError.DERBYREPO_0019, ex); } finally { closeStatements(stmt); } }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}//ww w . j a va 2 s . c o m * @since 3.1.2 */ @Override public FxScriptSchedule createScriptSchedule(FxScriptScheduleEdit scriptSchedule) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptManagement); FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptExecution); FxScriptSchedule ss; Connection con = null; PreparedStatement ps = null; String sql; boolean success = false; //check script existence FxScriptInfo si = CacheAdmin.getEnvironment().getScript(scriptSchedule.getScriptId()); //check for valid script event if (si.getEvent() != FxScriptEvent.Manual) throw new FxConstraintViolationException("ex.scripting.schedule.wrongScriptEvent"); //check consistency checkScriptScheduleConsistency(scriptSchedule); try { // for groovy scripts set cached flag to true ss = new FxScriptSchedule(seq.getId(FxSystemSequencer.SCRIPTS), scriptSchedule.getScriptId(), scriptSchedule.getName(), scriptSchedule.isActive(), scriptSchedule.getStartTime(), scriptSchedule.getEndTime(), scriptSchedule.getRepeatInterval(), scriptSchedule.getRepeatTimes(), scriptSchedule.getCronString()); // Obtain a database connection con = Database.getDbConnection(); // 1 2 3 4 5 6 7 8 9 sql = "INSERT INTO " + TBL_SCRIPT_SCHEDULES + " (ID,SCRIPT,SNAME,ACTIVE,STARTTIME,ENDTIME,REPEATINTERVAL,REPEATTIMES,CRONSTRING) VALUES (?,?,?,?,?,?,?,?,?)"; ps = con.prepareStatement(sql); ps.setLong(1, ss.getId()); ps.setLong(2, ss.getScriptId()); ps.setString(3, ss.getName()); ps.setBoolean(4, ss.isActive()); ps.setTimestamp(5, new Timestamp(ss.getStartTime().getTime())); ps.setTimestamp(6, ss.getEndTime() == null ? null : new Timestamp(ss.getEndTime().getTime())); ps.setLong(7, ss.getRepeatInterval()); ps.setInt(8, ss.getRepeatTimes()); ps.setString(9, ss.getCronString()); ps.executeUpdate(); if (EJBLookup.getTimerService().isInstalled()) { EJBLookup.getTimerService().scheduleScript(ss); } success = true; } catch (SQLException exc) { throw new FxCreateException(LOG, exc, "ex.scripting.schedule.create.failed", scriptSchedule.getName(), exc.getMessage()); } finally { Database.closeObjects(ScriptingEngineBean.class, con, ps); if (!success) EJBUtils.rollback(ctx); else StructureLoader.reloadScripting(FxContext.get().getDivisionId()); } return ss; }
From source file:org.apache.sqoop.repository.derby.DerbyRepositoryHandler.java
/** * {@inheritDoc}//from w ww .j a v a2 s.com */ @Override public void createJob(MJob job, Connection conn) { PreparedStatement stmt = null; int result; try { stmt = conn.prepareStatement(STMT_INSERT_JOB, Statement.RETURN_GENERATED_KEYS); stmt.setString(1, job.getName()); stmt.setLong(2, job.getLinkId(Direction.FROM)); stmt.setLong(3, job.getLinkId(Direction.TO)); stmt.setBoolean(4, job.getEnabled()); stmt.setString(5, job.getCreationUser()); stmt.setTimestamp(6, new Timestamp(job.getCreationDate().getTime())); stmt.setString(7, job.getLastUpdateUser()); stmt.setTimestamp(8, new Timestamp(job.getLastUpdateDate().getTime())); result = stmt.executeUpdate(); if (result != 1) { throw new SqoopException(DerbyRepoError.DERBYREPO_0012, Integer.toString(result)); } ResultSet rsetJobId = stmt.getGeneratedKeys(); if (!rsetJobId.next()) { throw new SqoopException(DerbyRepoError.DERBYREPO_0013); } long jobId = rsetJobId.getLong(1); // from config for the job createInputValues(STMT_INSERT_JOB_INPUT, jobId, job.getJobConfig(Direction.FROM).getConfigs(), conn); // to config for the job createInputValues(STMT_INSERT_JOB_INPUT, jobId, job.getJobConfig(Direction.TO).getConfigs(), conn); // driver config per job createInputValues(STMT_INSERT_JOB_INPUT, jobId, job.getDriverConfig().getConfigs(), conn); job.setPersistenceId(jobId); } catch (SQLException ex) { logException(ex, job); throw new SqoopException(DerbyRepoError.DERBYREPO_0026, ex); } finally { closeStatements(stmt); } }
From source file:com.krawler.esp.servlets.deskeramob_V1.java
public static String createProject(Connection conn, HttpServletRequest request, String companyid, String subdomain, String userid) throws ServiceException { String status = ""; DiskFileUpload fu = new DiskFileUpload(); java.util.List fileItems = null; PreparedStatement pstmt = null; String imageName = ""; try {/* w ww. j a va 2 s.co m*/ fileItems = fu.parseRequest(request); } catch (FileUploadException e) { throw ServiceException.FAILURE("Admin.createProject", e); } java.util.HashMap arrParam = new java.util.HashMap(); java.util.Iterator k = null; for (k = fileItems.iterator(); k.hasNext();) { FileItem fi1 = (FileItem) k.next(); arrParam.put(fi1.getFieldName(), fi1.getString()); } try { pstmt = conn .prepareStatement("select count(projectid) from project where companyid =? AND archived = 0"); pstmt.setString(1, companyid); ResultSet rs = pstmt.executeQuery(); int noProjects = 0; int maxProjects = 0; if (rs.next()) { noProjects = rs.getInt(1); } pstmt = conn.prepareStatement("select maxprojects from company where companyid =?"); pstmt.setString(1, companyid); rs = pstmt.executeQuery(); if (rs.next()) { maxProjects = rs.getInt(1); } if (noProjects == maxProjects) { return "The maximum limit for projects for this company has already reached"; } } catch (SQLException e) { throw ServiceException.FAILURE("ProfileHandler.getPersonalInfo", e); } try { String projectid = UUID.randomUUID().toString(); String projName = StringUtil.serverHTMLStripper(arrParam.get("projectname").toString() .replaceAll("[^\\w|\\s|'|\\-|\\[|\\]|\\(|\\)]", "").trim()); String nickName = AdminServlet.makeNickName(conn, projName, 1); if (StringUtil.isNullOrEmpty(projName)) { status = "failure"; } else { String qry = "INSERT INTO project (projectid,projectname,description,image,companyid, nickname) VALUES (?,?,?,?,?,?)"; pstmt = conn.prepareStatement(qry); pstmt.setString(1, projectid); pstmt.setString(2, projName); pstmt.setString(3, arrParam.get("aboutproject").toString()); pstmt.setString(4, imageName); pstmt.setString(5, companyid); pstmt.setString(6, nickName); int df = pstmt.executeUpdate(); if (df != 0) { pstmt = conn.prepareStatement( "INSERT INTO projectmembers (projectid, userid, status, inuseflag, planpermission) " + "VALUES (?, ?, ?, ?, ?)"); pstmt.setString(1, projectid); pstmt.setString(2, userid); pstmt.setInt(3, 4); pstmt.setBoolean(4, true); pstmt.setInt(5, 0); pstmt.executeUpdate(); } // /DbUtil.executeUpdate(conn,qry,new Object[] { projectid,projName,arrParam.get("aboutproject"), imageName,companyid, nickName}); if (arrParam.get("image").toString().length() != 0) { genericFileUpload uploader = new genericFileUpload(); uploader.doPost(fileItems, projectid, StorageHandler.GetProfileImgStorePath()); if (uploader.isUploaded()) { pstmt = null; // DbUtil.executeUpdate(conn, // "update project set image=? where projectid = ?", // new Object[] { // ProfileImageServlet.ImgBasePath + projectid // + uploader.getExt(), projectid }); pstmt = conn.prepareStatement("update project set image=? where projectid = ?"); pstmt.setString(1, ProfileImageServlet.ImgBasePath + projectid + "_200" + uploader.getExt()); pstmt.setString(2, projectid); pstmt.executeUpdate(); imageName = projectid + uploader.getExt(); } } com.krawler.esp.handlers.Forum.setStatusProject(conn, userid, projectid, 4, 0, "", subdomain); status = "success"; AdminServlet.setDefaultWorkWeek(conn, projectid); conn.commit(); } } catch (ConfigurationException e) { status = "failure"; throw ServiceException.FAILURE("Admin.createProject", e); } catch (SQLException e) { status = "failure"; throw ServiceException.FAILURE("Admin.createProject", e); } return status; }
From source file:org.apache.sqoop.repository.derby.DerbyRepositoryHandler.java
/** * Save given inputs to the database.//from w w w . ja va 2 s .c om * * Use given prepare statement to save all inputs into repository. * * @param configId Identifier for corresponding config * @param inputs List of inputs that needs to be saved * @param baseInputStmt Statement that we can utilize * @throws SQLException In case of any failure on Derby side */ private void registerConfigInputs(long configId, List<MInput<?>> inputs, PreparedStatement baseInputStmt) throws SQLException { short inputIndex = 0; for (MInput<?> input : inputs) { baseInputStmt.setString(1, input.getName()); baseInputStmt.setLong(2, configId); baseInputStmt.setShort(3, inputIndex++); baseInputStmt.setString(4, input.getType().name()); baseInputStmt.setBoolean(5, input.isSensitive()); // String specific column(s) if (input.getType().equals(MInputType.STRING)) { MStringInput strInput = (MStringInput) input; baseInputStmt.setShort(6, strInput.getMaxLength()); } else { baseInputStmt.setNull(6, Types.INTEGER); } // Enum specific column(s) if (input.getType() == MInputType.ENUM) { baseInputStmt.setString(7, StringUtils.join(((MEnumInput) input).getValues(), ",")); } else { baseInputStmt.setNull(7, Types.VARCHAR); } int baseInputCount = baseInputStmt.executeUpdate(); if (baseInputCount != 1) { throw new SqoopException(DerbyRepoError.DERBYREPO_0017, Integer.toString(baseInputCount)); } ResultSet rsetInputId = baseInputStmt.getGeneratedKeys(); if (!rsetInputId.next()) { throw new SqoopException(DerbyRepoError.DERBYREPO_0018); } long inputId = rsetInputId.getLong(1); input.setPersistenceId(inputId); } }