List of usage examples for java.sql Types INTEGER
int INTEGER
To view the source code for java.sql Types INTEGER.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER
.
From source file:info.smartkit.hairy_batman.query.KJsonApiQuery.java
public void query() { // KJSON API testing using RestTemplate. RestTemplate restTemplate = new RestTemplate(); // restTemplate.getMessageConverters().add(new // StringHttpMessageConverter()); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); // @see:/*from w ww . ja v a2s . c o m*/ // http://stackoverflow.com/questions/22329368/spring-android-rest-template-parse-json-data-with-content-type-text-html converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML)); restTemplate.getMessageConverters().add(converter); // Spring batch for CSV reading. // WxBar api_query_resutls = new WxBar(); try { /*System.out.println("this.getParameters():" + this.getParameters()); api_query_resutls = restTemplate.postForObject( GlobalConsts.KJSON_API_URI, this.getParameters(), WxBar.class);*/ } catch (RestClientException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (api_query_resutls.getData() != null) {// FIXME: null JSON // exception handler // here. // WxBar returns = // restTemplate.getForObject(GlobalConsts.KJSON_API_URI, // WxBar.class); ArrayList<WxKJson> api_query_resutls_data = api_query_resutls.getData(); // System.out.println("ApiQuery result data: " + // api_query_resutls_data); LOG.info("ApiQuery result data: " + api_query_resutls_data.toString()); WxKJson wxKJson = api_query_resutls_data.get(0); // System.out.println("Parsed ApiQuery results,articleReadNum:" + // wxKJson.getRead() + ",articleLikeNum: " // + wxKJson.getLike()); LOG.info("Parsed ApiQuery results,articleReadNum:" + wxKJson.getRead() + ",articleLikeNum: " + wxKJson.getLike()); // this.readNum = Long.parseLong(wxKJson.getRead()); this.likeNum = Long.parseLong(wxKJson.getLike()); this.queriedSubscriber.setArticleReadNum(wxKJson.getRead()); this.queriedSubscriber.setArticleLikeNum(wxKJson.getLike()); double likeRate = (double) likeNum / readNum * 100; java.math.BigDecimal bigLikeRate = new java.math.BigDecimal(likeRate); String bigLikeRateStr = bigLikeRate .setScale(GlobalConsts.DEFINITION_PRECISION, java.math.BigDecimal.ROUND_HALF_UP).doubleValue() + "%"; this.queriedSubscriber.setArticleLikeRate(bigLikeRateStr); // this.queriedSubscriber.setMoniterTime(GlobalVariables.now()); this.queriedSubscriber.setArticleUrl(wxKJson.getUrl()); // GlobalVariables.wxFooListWithOpenIdArticleReadLike.add(this.queriedSubscriber); // File reporting... new FileReporter(GlobalConsts.REPORT_FILE_OUTPUT_OPENID_ARITICLE_READ_LIKE, GlobalVariables.wxFooListWithOpenIdArticleReadLike, FileReporter.REPORTER_TYPE.R_T_OPENID_ARTICLE_READ_LIKE, FileReporter.REPORTER_FILE_TYPE.EXCEL) .write(); // Save to DB. Object[] params = { likeNum.intValue(), readNum.intValue(), this.queriedSubscriber.getArticleLikeRate(), this.queriedSubscriber.getArticleUrl() }; int[] types = { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR }; int rows = GlobalVariables.jdbcTempate.update(GlobalConsts.JDBC_QUERY_UPDATE_OPENID_ARTICLE_READ_LIKE, params, types); LOG.info("rows(s): " + rows + " updated." + ",likeNum: " + likeNum + ",readNum: " + readNum + ",bigLikeRateStr: " + bigLikeRateStr + ",articleUrl: " + this.queriedSubscriber.getArticleUrl()); // LOG.info("GlobalVariables.wxFooListWithOpenIdArticleReadLike(size):" + GlobalVariables.wxFooListWithOpenIdArticleReadLike.size() + ",raw: " + GlobalVariables.wxFooListWithOpenIdArticleReadLike.toString()); // if (this.subscribers.size() > 0) { this.query();// Recursively call. GlobalVariables.kjsonQueryCounter++; if (GlobalVariables.kjsonQueryCounter >= GlobalConsts.KJSON_API_QPM) { try { Thread.sleep(30000); GlobalVariables.kjsonQueryCounter = 0; } catch (InterruptedException e) { LOG.error(e.toString()); } } } else { // } } }
From source file:com.wso2telco.dep.ratecardservice.dao.TariffDAO.java
public TariffDTO addTariff(TariffDTO tariff) throws BusinessException { Connection con = null;//from ww w . j a va 2 s .c o m PreparedStatement ps = null; ResultSet rs = null; Integer tariffId = 0; try { con = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_RATE_DB); if (con == null) { log.error("unable to open " + DataSourceNames.WSO2TELCO_RATE_DB + " database connection"); throw new BusinessException(ServiceError.SERVICE_ERROR_OCCURED); } StringBuilder query = new StringBuilder("insert into "); query.append(DatabaseTables.TARIFF.getTObject()); query.append( " (tariffname, tariffdesc, tariffdefaultval, tariffmaxcount, tariffexcessrate, tariffdefrate, tariffspcommission, tariffadscommission, tariffopcocommission, tariffsurchargeval, tariffsurchargeAds, tariffsurchargeOpco, createdby)"); query.append(" values"); query.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); ps = con.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); log.debug("sql query in addTariff : " + ps); ps.setString(1, tariff.getTariffName()); ps.setString(2, tariff.getTariffDescription()); Double tariffDefaultVal = tariff.getTariffDefaultVal(); if (tariffDefaultVal != null) { ps.setDouble(3, tariffDefaultVal); } else { ps.setNull(3, Types.DOUBLE); } Integer tariffMaxCount = tariff.getTariffMaxCount(); if (tariffMaxCount != null) { ps.setInt(4, tariffMaxCount); } else { ps.setNull(4, Types.INTEGER); } Double tariffExcessRate = tariff.getTariffExcessRate(); if (tariffExcessRate != null) { ps.setDouble(5, tariffExcessRate); } else { ps.setNull(5, Types.DOUBLE); } Double tariffDefRate = tariff.getTariffDefRate(); if (tariffDefRate != null) { ps.setDouble(6, tariffDefRate); } else { ps.setNull(6, Types.DOUBLE); } Double tariffSPCommission = tariff.getTariffSPCommission(); if (tariffSPCommission != null) { ps.setDouble(7, tariffSPCommission); } else { ps.setNull(7, Types.DOUBLE); } Double tariffAdsCommission = tariff.getTariffAdsCommission(); if (tariffAdsCommission != null) { ps.setDouble(8, tariffAdsCommission); } else { ps.setNull(8, Types.DOUBLE); } Double tariffOpcoCommission = tariff.getTariffOpcoCommission(); if (tariffOpcoCommission != null) { ps.setDouble(9, tariffOpcoCommission); } else { ps.setNull(9, Types.DOUBLE); } Double tariffSurChargeval = tariff.getTariffSurChargeval(); if (tariffSurChargeval != null) { ps.setDouble(10, tariffSurChargeval); } else { ps.setNull(10, Types.DOUBLE); } Double tariffSurChargeAds = tariff.getTariffSurChargeAds(); if (tariffSurChargeAds != null) { ps.setDouble(11, tariffSurChargeAds); } else { ps.setNull(11, Types.DOUBLE); } Double tariffSurChargeOpco = tariff.getTariffSurChargeOpco(); if (tariffSurChargeOpco != null) { ps.setDouble(12, tariffSurChargeOpco); } else { ps.setNull(12, Types.DOUBLE); } ps.setString(13, tariff.getCreatedBy()); ps.executeUpdate(); rs = ps.getGeneratedKeys(); while (rs.next()) { tariffId = rs.getInt(1); } tariff.setTariffId(tariffId); } catch (SQLException e) { log.error("database operation error in addTariff : ", e); throw new BusinessException(ServiceError.SERVICE_ERROR_OCCURED); } catch (Exception e) { log.error("error in addTariff : ", e); throw new BusinessException(ServiceError.SERVICE_ERROR_OCCURED); } finally { DbUtils.closeAllConnections(ps, con, rs); } return tariff; }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlAttachmentTable.java
public void createAttachment(CFCrmAuthorization Authorization, CFCrmAttachmentBuff Buff) { final String S_ProcName = "createAttachment"; if ("ATTC".equals(Buff.getClassCode()) && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "CreateAttachment"))) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Permission denied -- User not part of TSecGroup CreateAttachment"); }//from www .j a v a2 s . c om if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long AttachmentId = schema.getTableTenant().nextAttachmentIdGen(Authorization, Buff.getRequiredTenantId()); long ContactId = Buff.getRequiredContactId(); String Description = Buff.getRequiredDescription(); Integer MimeTypeId = Buff.getOptionalMimeTypeId(); String Attachment = Buff.getRequiredAttachment(); int Revision = 1; String sql = "INSERT INTO " + schema.getLowerDbSchemaName() + "..Attchmnt( " + "forcesynclock, " + "createdby, " + "createdat, " + "updatedby, " + "updatedat, " + "tenantid, " + "attachmentid, " + "contactid, " + "description, " + "mimetypeid, " + "attachment" + ", revision )" + "VALUES ( " + "0, " + " ?, " + " getdate(), " + " ?, " + " getdate(), " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "1 )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, AttachmentId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setString(argIdx++, Description); if (MimeTypeId != null) { stmtCreateByPKey.setInt(argIdx++, MimeTypeId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } stmtCreateByPKey.setString(argIdx++, Attachment); int rowsAffected = stmtCreateByPKey.executeUpdate(); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by insert, not " + rowsAffected); } Buff.setRequiredAttachmentId(AttachmentId); Buff.setRequiredRevision(Revision); String sqlAuditCreated = "INSERT INTO " + schema.getLowerDbSchemaName() + "..Attchmnt_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "tenantid" + ", " + "attachmentid" + ", " + "contactid" + ", " + "description" + ", " + "mimetypeid" + ", " + "attachment" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", " + "attc.tenantid" + ", " + "attc.attachmentid" + ", " + "attc.contactid" + ", " + "attc.description" + ", " + "attc.mimetypeid" + ", " + "attc.attachment" + ", " + " attc.revision, " + " 1" + "FROM " + schema.getLowerDbSchemaName() + "..Attchmnt AS attc " + " WHERE " + "attc.tenantid = ? " + "AND attc.attachmentid = ? "; if (stmtAuditCreatedByPKey == null) { stmtAuditCreatedByPKey = cnx.prepareStatement(sqlAuditCreated); } argIdx = 1; stmtAuditCreatedByPKey.setLong(argIdx++, Authorization.getSecClusterId()); stmtAuditCreatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString()); stmtAuditCreatedByPKey.setLong(argIdx++, TenantId); stmtAuditCreatedByPKey.setLong(argIdx++, AttachmentId); int rowsAudited = stmtAuditCreatedByPKey.executeUpdate(); if (rowsAudited != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java
@Override protected void setStoreStatementValues(PowerDatum datum, PreparedStatement ps) throws SQLException { int col = 1;/*from ww w.j a va2 s . co m*/ ps.setTimestamp(col++, new java.sql.Timestamp( datum.getCreated() == null ? System.currentTimeMillis() : datum.getCreated().getTime())); ps.setString(col++, datum.getSourceId() == null ? "" : datum.getSourceId()); if (datum.getLocationId() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getLocationId()); } if (datum.getWatts() == null) { ps.setNull(col++, Types.INTEGER); } else { ps.setInt(col++, datum.getWatts()); } if (datum.getBatteryVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getBatteryVolts()); } if (datum.getBatteryAmpHours() == null) { ps.setNull(col++, Types.DOUBLE); } else { ps.setDouble(col++, datum.getBatteryAmpHours()); } if (datum.getDcOutputVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getDcOutputVolts()); } if (datum.getDcOutputAmps() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getDcOutputAmps()); } if (datum.getAcOutputVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getAcOutputVolts()); } if (datum.getAcOutputAmps() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getAcOutputAmps()); } if (datum.getWattHourReading() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getWattHourReading()); } if (datum.getAmpHourReading() == null) { ps.setNull(col++, Types.DOUBLE); } else { ps.setDouble(col++, datum.getAmpHourReading()); } }
From source file:com.streamsets.pipeline.stage.it.DriftIT.java
@Test public void testRenameColumn() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); List<Record> records = new LinkedList<>(); Map<String, Field> map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); map.put("old_column", Field.create(Field.Type.STRING, "old_value")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record);// ww w. ja v a 2 s. c om map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 2)); map.put("new_column", Field.create(Field.Type.STRING, "new_value")); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record); processRecords(processor, hiveTarget, records); assertQueryResult("select * from tbl order by id", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.id", Types.INTEGER), new ImmutablePair("tbl.old_column", Types.VARCHAR), new ImmutablePair("tbl.new_column", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals(1, rs.getLong(1)); Assert.assertEquals("old_value", rs.getString(2)); Assert.assertEquals(null, rs.getString(3)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(2, rs.getLong(1)); Assert.assertEquals(null, rs.getString(2)); Assert.assertEquals("new_value", rs.getString(3)); Assert.assertFalse("Unexpected number of rows", rs.next()); } }); }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
public int storeData(DataList list) { try {//w ww. j av a 2 s . c o m Connection conn = dataSourceWrite.getConnection(); if (conn != null) { int i; DataItem item; EventItem event; Object tag; conn.setAutoCommit(false); PreparedStatement stmt; Date t1 = new Date(); stmt = conn.prepareStatement(sqlInsertStmt); for (i = 0; i <= list.getHighWaterMark() && (item = list.getItem(i)) != null; i++) { if (!(item instanceof EventItem)) continue; event = (EventItem) item; ValueItem val = event.getValue(); tag = this.getTagOfDp(event.getDp()); if (tag == null) continue; if (tag instanceof Long) stmt.setLong(1, (Long) tag); else if (tag instanceof String) stmt.setString(1, (String) tag); java.sql.Timestamp ts = new java.sql.Timestamp(event.getTimeMS()); ts.setNanos(event.getNanos()); stmt.setTimestamp(2, ts, cal); Double dval = val.getDouble(); if (dval != null) { stmt.setDouble(3, dval); } else { stmt.setNull(3, Types.DOUBLE); } // value_string stmt.setString(4, val.getString()); // value_timestamp if (val.getTimeMS() != null) stmt.setTimestamp(5, new java.sql.Timestamp(val.getTimeMS()), cal); else stmt.setNull(5, Types.TIMESTAMP); // status, manager, user if (event.hasAttributes()) { stmt.setLong(6, event.getStatus()); stmt.setInt(7, event.getManager()); stmt.setInt(8, event.getUser()); } else { stmt.setNull(6, Types.INTEGER); stmt.setNull(7, Types.INTEGER); stmt.setNull(8, Types.INTEGER); } //JDebug.out.log(Level.FINE, "{0}:{1}/{2} [{3}]", new Object[] {i, element_id.toString(), ts.toString(), item.toString()}); stmt.addBatch(); } try { stmt.executeBatch(); // TODO check result? int[] res = } catch (BatchUpdateException ex) { JDebug.out.log(Level.SEVERE, "Batch exception {0} update count {1}.", new Object[] { ex.getErrorCode(), ex.getUpdateCounts().length }); JDebug.StackTrace(Level.SEVERE, ex); } catch (SQLException ex) { SQLException current = ex; do { JDebug.out.log(Level.SEVERE, "SQL exception {0}.", new Object[] { ex.getErrorCode() }); JDebug.StackTrace(Level.SEVERE, current); } while ((current = current.getNextException()) != null); // for (i = 0; i <= list.getHighWaterMark() && (item = list.getItem(i)) != null; i++) { // JDebug.out.log(Level.INFO, "{0}", item.toJSONObject()); // } } Date t2 = new Date(); stmt.close(); afterInsert(conn); conn.commit(); conn.close(); addServerStats(list.getHighWaterMark(), t2.getTime() - t1.getTime()); return INoSQLInterface.OK; } else { JDebug.StackTrace(Level.SEVERE, "no connection!"); return INoSQLInterface.ERR_REPEATABLE; } } catch (Exception ex) { JDebug.StackTrace(Level.SEVERE, ex); return INoSQLInterface.ERR_REPEATABLE; } }
From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ?CIQ?// w ww .j ava 2s . c om * --?0??0 */ public static int saveCIQDeclInfo(CEMSDeclDataDto declDto) { int retCode = -1; Connection conn = null; CallableStatement proc = null; String call = "{call Pro_SaveCIQDeclInfo(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"; try { conn = DBPool.ds.getConnection(); proc = conn.prepareCall(call); proc.setString(1, declDto.getDecl_No()); proc.setString(2, declDto.getDecl_Get_No()); proc.setString(3, declDto.getDecl_Reg_No()); proc.setString(4, declDto.getDecl_Person_Code()); proc.setString(5, declDto.getDecl_Date()); proc.setString(6, declDto.getEnt_Property()); proc.setString(7, declDto.getConsignor_Code()); proc.setString(8, declDto.getConsignor_CName()); proc.setString(9, declDto.getConsignor_EName()); proc.setString(10, declDto.getConsignee_Code()); proc.setString(11, declDto.getConsignee_CName()); proc.setString(12, declDto.getConsignee_EName()); proc.setString(13, declDto.getTrans_Type_Code()); proc.setString(14, declDto.getTrans_Means_Code()); proc.setString(15, declDto.getTonnage()); proc.setString(16, declDto.getTrade_Mode_Code()); proc.setString(17, declDto.getGoods_Place_Code()); proc.setString(18, declDto.getGoods_Place()); proc.setString(19, declDto.getPurpose_Code()); proc.setString(20, declDto.getDecl_Date()); proc.setString(21, declDto.getArri_Date()); proc.setString(22, declDto.getUnload_Date()); proc.setString(23, declDto.getDesp_Port_Code()); proc.setString(24, declDto.getArri_Port_Code()); proc.setString(25, declDto.getEntry_Port_Code()); proc.setString(26, declDto.getVia_Port_Code()); proc.setString(27, declDto.getDest_Code()); proc.setString(28, declDto.getTrade_Country_Code()); proc.setString(29, declDto.getDesp_Country_Code()); proc.setString(30, declDto.getSituation_Code()); proc.setString(31, declDto.getSituation_Level()); proc.setString(32, declDto.getCounter_Claim()); proc.setString(33, declDto.getContract_No()); proc.setString(34, declDto.getCarrier_Note_No()); proc.setString(35, declDto.getLicense_Code()); proc.setString(36, declDto.getApprove_Code()); proc.setString(37, declDto.getProd_Reg_No()); proc.setString(38, declDto.getExchange_Note_Codes()); proc.setString(39, declDto.getExchange_Note_Num()); proc.setString(40, declDto.getPack_Cap_Resu_Codes()); proc.setString(41, declDto.getPack_Use_Resu_Codes()); proc.setString(42, declDto.getSheet_Type_Codes()); proc.setString(43, declDto.getCert_Type_Codes()); proc.setString(44, declDto.getCert_Originals()); proc.setString(45, declDto.getCert_Copies()); proc.setString(46, declDto.getSpecial_Require()); proc.setString(47, declDto.getMark_No()); proc.setString(48, declDto.getValue_Checkup_Flag()); proc.setString(49, declDto.getInsp_Mode_Code()); proc.setString(50, declDto.getInsp_Org_Code()); proc.setString(51, declDto.getInsp_Dept_1()); proc.setString(52, declDto.getInsp_Dept_2()); proc.setString(53, declDto.getInsp_Dept_3()); proc.setString(54, declDto.getInsp_Dept_4()); proc.setString(55, declDto.getInsp_Dept_5()); proc.setString(56, declDto.getDecl_Type_Code()); proc.setString(57, declDto.getProcess_Status()); proc.setString(58, declDto.getFee_Status()); proc.setString(59, declDto.getValues_USD()); proc.setString(60, declDto.getValues_RMB()); proc.setString(61, declDto.getOperator_Code()); proc.setString(62, declDto.getOperate_Date()); proc.setString(63, declDto.getStat_Flag()); proc.setString(64, declDto.getWaste_Flag()); proc.setString(65, declDto.getRelease_Status()); proc.setString(66, declDto.getCheckup_Type_Code()); proc.setString(67, declDto.getCheckup_Work_Code()); proc.setString(68, declDto.getOrg_Code()); proc.setString(69, declDto.getDept_Code()); proc.setString(70, declDto.getDest_Org_Code()); proc.setString(71, declDto.getFlow_Flag()); proc.setString(72, declDto.getTrans_Flag()); proc.setString(73, declDto.getInputer_Code()); proc.setString(74, declDto.getInput_Date()); proc.setString(75, declDto.getEnt_Decl_No()); proc.setString(76, declDto.getO_I_Flag()); proc.setString(77, declDto.getChg_Org_Code()); proc.setString(78, declDto.getChg_Person_Code()); proc.setString(79, declDto.getChg_Date()); proc.setString(80, declDto.getCheck_Flag()); proc.setString(81, declDto.getInput_Org_Code()); proc.setString(82, declDto.getDECL_FLAG()); proc.setString(83, declDto.getCUSTOM_CODE()); proc.setString(84, declDto.getAUTO_PASS_FLAG()); proc.setString(85, declDto.getAUTO_CHECK_FLAG()); proc.setString(86, declDto.getBACK_TRANSPORT_FLAG()); proc.setString(87, declDto.getCONTACTOR()); proc.setString(88, declDto.getTELEPHONE()); proc.setString(89, declDto.getPROCESS_FLAG()); proc.setString(90, declDto.getMONITOR_PASS_FLAG()); proc.setString(91, declDto.getCOMPUTE_PASS_FLAG()); proc.setString(92, declDto.getTRANS_MEANS_NAME()); proc.setString(93, declDto.getMONITOR_FLAG()); proc.setString(94, declDto.getSPOTTEST_FLAG()); proc.setString(95, declDto.getCOMB_BATCH_NO()); proc.setString(96, declDto.getRESEND_NUM()); proc.setString(97, declDto.getCHANGE_INSP_DEPT_FLAG()); proc.setString(98, declDto.getCIQ2000_ASSIGN_FLAG()); proc.setString(99, declDto.getMonitor_Decl_Flag()); proc.setString(100, declDto.getSEQ_NUM()); proc.registerOutParameter(101, Types.INTEGER); proc.execute(); retCode = proc.getInt(101); } catch (SQLException e) { // TODO Auto-generated catch block log.error("num9", e); } catch (Exception e) { log.error("num10", e); } finally { try { if (proc != null) { proc.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block log.error("num11", e); } } return retCode; }
From source file:net.ontopia.persistence.rdbms.CSVImport.java
public void importCSV(InputStream csvfile) throws Exception { // Execute statements try {/* w w w . java 2 s. c om*/ String[] qmarks = new String[columns.length]; for (int i = 0; i < qmarks.length; i++) { qmarks[i] = "?"; } if (cleartable) { String delsql = "delete from " + table; Statement delstm = conn.createStatement(); delstm.executeUpdate(delsql); //! conn.commit(); } String sql = "insert into " + table + " (" + StringUtils.join(columns, ", ") + ") values (" + StringUtils.join(qmarks, ", ") + ")"; log.debug("SQL: " + sql); PreparedStatement stm = conn.prepareStatement(sql); int datatypes[] = new int[columns.length]; for (int i = 0; i < columns.length; i++) { Table tbl = project.getTableByName(table); if (tbl == null) throw new OntopiaRuntimeException("Unknown table: " + table); Column col = tbl.getColumnByName(columns[i]); if (col == null) throw new OntopiaRuntimeException("Unknown table column: " + columns[i]); if (col.getType() == null) throw new OntopiaRuntimeException("Column type is null: " + col.getType()); DataType datatype = project.getDataTypeByName(col.getType(), "generic"); if (datatype == null) throw new OntopiaRuntimeException("Unknown column type: " + col.getType()); String dtype = datatype.getType(); if ("varchar".equals(dtype)) datatypes[i] = Types.VARCHAR; else if ("integer".equals(dtype)) datatypes[i] = Types.INTEGER; else throw new OntopiaRuntimeException("Unknown datatype: " + dtype); } LineNumberReader reader = new LineNumberReader(new InputStreamReader(csvfile)); // Ignore first X lines for (int i = 0; i < ignorelines; i++) { String line = reader.readLine(); if (line == null) break; } // Process input log.debug("[" + StringUtils.join(columns, ", ") + "]"); int lineno = 0; while (true) { lineno++; String line = reader.readLine(); if (line == null) break; try { String[] cols = StringUtils.split(line, separator); if (cols.length > columns.length && !ignorecolumns) log.debug("Ignoring columns: " + (columns.length + 1) + "-" + cols.length + " '" + line + "'"); log.debug("CVALUES: " + (columns.length + 1) + "-" + cols.length + " '" + line + "'"); String dmesg = "("; for (int i = 0; i < columns.length; i++) { String col = cols[i]; // If first column character is '"' strip quotes. if (stripquotes) { int len = col.length(); if (len > 1 && ((col.charAt(0) == '"' && col.charAt(len - 1) == '"') || (col.charAt(0) == '\'' && col.charAt(len - 1) == '\''))) col = col.substring(1, len - 1); } if (col != null && col.equals("")) col = null; dmesg = dmesg + col; if (i < columns.length - 1) dmesg = dmesg + ", "; stm.setObject(i + 1, col, datatypes[i]); } dmesg = dmesg + ")"; log.debug(dmesg); stm.execute(); } catch (Exception e) { conn.rollback(); throw new OntopiaRuntimeException("Cannot read line " + lineno + ": '" + line + "'", e); } } conn.commit(); } finally { if (conn != null) conn.close(); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWAttachmentTable.java
public void createAttachment(CFAccAuthorization Authorization, CFAccAttachmentBuff Buff) { final String S_ProcName = "createAttachment"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }// ww w .ja va2 s . c o m ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); long ContactId = Buff.getRequiredContactId(); String Description = Buff.getRequiredDescription(); Integer MimeTypeId = Buff.getOptionalMimeTypeId(); String Attachment = Buff.getRequiredAttachment(); Connection cnx = schema.getCnx(); final String sql = "CALL sp_create_attchmnt( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, "ATTC"); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setString(argIdx++, Description); if (MimeTypeId != null) { stmtCreateByPKey.setInt(argIdx++, MimeTypeId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } stmtCreateByPKey.setString(argIdx++, Attachment); resultSet = stmtCreateByPKey.executeQuery(); if (resultSet.next()) { CFAccAttachmentBuff createdBuff = unpackAttachmentResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredAttachmentId(createdBuff.getRequiredAttachmentId()); Buff.setRequiredContactId(createdBuff.getRequiredContactId()); Buff.setRequiredDescription(createdBuff.getRequiredDescription()); Buff.setOptionalMimeTypeId(createdBuff.getOptionalMimeTypeId()); Buff.setRequiredAttachment(createdBuff.getRequiredAttachment()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlAttachmentTable.java
public void createAttachment(CFAccAuthorization Authorization, CFAccAttachmentBuff Buff) { final String S_ProcName = "createAttachment"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/* ww w .j a va 2 s . co m*/ ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); long ContactId = Buff.getRequiredContactId(); String Description = Buff.getRequiredDescription(); Integer MimeTypeId = Buff.getOptionalMimeTypeId(); String Attachment = Buff.getRequiredAttachment(); Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerSchemaDbName() + ".sp_create_attchmnt( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, "ATTC"); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setString(argIdx++, Description); if (MimeTypeId != null) { stmtCreateByPKey.setInt(argIdx++, MimeTypeId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } stmtCreateByPKey.setString(argIdx++, Attachment); try { resultSet = stmtCreateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFAccAttachmentBuff createdBuff = unpackAttachmentResultSetToBuff(resultSet); if ((resultSet != null) && resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredAttachmentId(createdBuff.getRequiredAttachmentId()); Buff.setRequiredContactId(createdBuff.getRequiredContactId()); Buff.setRequiredDescription(createdBuff.getRequiredDescription()); Buff.setOptionalMimeTypeId(createdBuff.getOptionalMimeTypeId()); Buff.setRequiredAttachment(createdBuff.getRequiredAttachment()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }