List of usage examples for java.sql CallableStatement setString
void setString(String parameterName, String x) throws SQLException;
String
value. From source file:com.medlog.webservice.services.tone.ToneProcessorFactory.java
private static ArrayList<Integer> processTone(DbConnection dbc, ToneAnalysis tone, int diaryID) { CallableStatement cs = null; String cat_id = ""; ArrayList<Integer> results = new ArrayList<Integer>(); try {//from www . j a v a2 s. c o m //category , tone , sentance,score,text List<com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory> to = tone.getDocumentTone() .getTones(); Connection conn = dbc.getConnnection(); cs = conn.prepareCall(new StringBuilder().append("{call spDiaryTextScoreInsert(").append(diaryID) .append(",?,?,?,?,?)}").toString()); conn.setAutoCommit(false); cs.setInt(3, 0); cs.setNull(5, java.sql.Types.NVARCHAR);// cat_id); for (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory docTC : to) { cat_id = docTC.getId(); cs.setString(1, cat_id); for (ToneScore s : docTC.getTones()) { cs.setString(2, s.getId()); cs.setDouble(4, s.getScore()); cs.addBatch(); } } System.out.println("com.medlog.webservice.util.ToneAnalyzerExample.processTone() Process " + tone.getSentencesTone().size() + " sentances."); int[] docRes = cs.executeBatch(); List l = Arrays.asList(docRes); results.addAll(l); cs.clearBatch(); System.out.println("com.medlog.webservice.util.ToneAnalyzerExample.processTone() result --- " + ArrayUtils.toString(docRes)); int[] sentRes = null; for (SentenceTone sentT : tone.getSentencesTone()) { to = sentT.getTones(); cs.setInt(3, sentT.getId()); cs.setString(5, toS(sentT.getText()).trim()); for (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory docTC : to) { cat_id = docTC.getId(); cs.setString(1, cat_id); try { for (ToneScore s : docTC.getTones()) { cs.setString(2, s.getId()); cs.setDouble(4, s.getScore()); cs.addBatch(); } if (DEBUG) { DbUtl.getWarningsFromStatement(cs); } // sentRes = cs.executeBatch(); // List l = Arrays.asList(sentRes); // results.addAll(l); } catch (SQLException s) { System.err.println( "com.medlog.webservice.services.tone.ToneProcessorFactory.processTone(loop)" + DbUtl.printJDBCExceptionMsg(s)); s.printStackTrace(); } catch (Exception s) { } System.out.println("com.medlog.webservice.util.ToneAnalyzerExample.processTone() result[" + sentT.getId() + "] " + ArrayUtils.toString(sentRes)); } } sentRes = cs.executeBatch(); try { l = Arrays.asList(sentRes); results.addAll(l); conn.setAutoCommit(true); cs.clearBatch(); } catch (Exception e) { e.printStackTrace(); try { conn.setAutoCommit(true); } catch (Exception eeee) { eeee.printStackTrace(); } } } catch (BatchUpdateException ex) { Logger.getLogger(ToneAnalyzerExample.class.getName()).log(Level.SEVERE, null, ex); System.err.println("com.medlog.webservice.services.tone.ToneProcessorFactory.processTone(batch)" + DbUtl.printBatchUpdateException(ex)); } catch (SQLTimeoutException ex) { Logger.getLogger(ToneAnalyzerExample.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } catch (SQLException ex) { Logger.getLogger(ToneAnalyzerExample.class.getName()).log(Level.SEVERE, null, ex); System.err.println("com.medlog.webservice.services.tone.ToneProcessorFactory.processTone(meth)" + DbUtl.printJDBCExceptionMsg(ex)); } finally { DbUtl.close(cs); } return results; }
From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ?CIQ?/*from w w w .j ava 2 s . com*/ * --?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:de.whs.poodle.repositories.CourseRepository.java
public void edit(Course course) { try {/* w w w .j a v a 2 s .com*/ jdbc.update(con -> { CallableStatement cs = con.prepareCall("{ CALL update_course(?,?,?,?,?,?) }"); cs.setInt(1, course.getId()); cs.setString(2, course.getName()); cs.setBoolean(3, course.getVisible()); if (course.getPassword().trim().isEmpty()) cs.setNull(4, Types.VARCHAR); else cs.setString(4, course.getPassword()); Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray()); cs.setArray(5, otherInstructors); Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray()); cs.setArray(6, linkedCourses); return cs; }); } catch (DuplicateKeyException e) { throw new BadRequestException(); } }
From source file:com.mobilewallet.common.dao.RegisterDAO.java
public void updateGCM(String userId, String gcmId) { Connection con = null;// w ww . ja v a2 s . c om CallableStatement cstmt = null; try { con = ds.getConnection(); cstmt = con.prepareCall("{call wp_update_gcm(?,?,?)}"); cstmt.setString(1, userId); cstmt.setString(2, gcmId); cstmt.registerOutParameter(3, java.sql.Types.VARCHAR); cstmt.execute(); } catch (Exception ex) { } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (con != null) { con.close(); } } catch (Exception ex) { } } }
From source file:com.mobilewallet.common.dao.FeedBackDAO.java
public void feedBack(long userId, String feedType, String feedText, String ip, String email) { Connection connection = null; CallableStatement cstmt = null; try {//from ww w. j a va2 s .co m connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call FEEDBACK_PROC(?,?,?,?,?)}"); cstmt.setLong(1, userId); cstmt.setString(2, feedType); cstmt.setString(3, feedText); cstmt.setString(4, email); cstmt.setString(5, ip); cstmt.execute(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyCompressTableJob.java
@Override protected void executeInternal(JobExecutionContext jobContext) throws Exception { if (log.isDebugEnabled()) { log.debug("Compressing Derby table " + schema + '.' + table + " with purgeRows = " + purgeRows + ", defragmentRows = " + defragmentRows + ", truncateEnd = " + truncateEnd); }/* ww w. j a v a 2 s .c o m*/ jdbcOperations.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection con) throws SQLException { if (log.isTraceEnabled()) { log.trace("Preparing Derby compress table call [" + COMPRESS_CALL + ']'); } return con.prepareCall(COMPRESS_CALL); } }, new CallableStatementCallback<Object>() { public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { int idx = 1; cs.setString(idx++, schema); cs.setString(idx++, table); cs.setShort(idx++, purgeRows ? (short) 1 : (short) 0); cs.setShort(idx++, defragmentRows ? (short) 1 : (short) 0); cs.setShort(idx++, truncateEnd ? (short) 1 : (short) 0); boolean result = cs.execute(); if (log.isTraceEnabled()) { log.trace("Derby compress table call returned [" + result + ']'); } return null; } }); if (log.isInfoEnabled()) { log.info("Compressed Derby table " + schema + '.' + table); } }
From source file:com.yoncabt.ebr.jdbcbridge.pool.DataSource.java
private void fillHint(Connection connection, String client, String module, String action) { if (connection.getClass().getName().startsWith("oracle")) { //dier veritabanlar iin bakmak lazm try {/*from w w w .j a v a 2s . co m*/ CallableStatement call; call = connection.prepareCall("call dbms_application_info.set_client_info(?)"); call.setString(1, client); call.execute(); call = connection .prepareCall("call dbms_application_info.set_module(module_name => ?, action_name => ?)"); call.setString(1, module); call.setString(2, action); call.execute(); } catch (SQLException ex) { logManager.error(ex); } } }
From source file:org.devgateway.toolkit.forms.service.DerbyDatabaseBackupService.java
/** * Backup the On-Line Derby database. This temporarily locks the db in * readonly mode/*from www . jav a 2 s . c o m*/ * * Invokes SYSCS_BACKUP_DATABASE and dumps the database to the temporary * directory Use {@link ZipUtil#pack(File, File)} to zip the directory * Deletes the temporary directory * * @see #createBackupURL(String) */ private void backupDerbyDatabase() { lastBackupURL = createBackupURL(); CallableStatement cs = null; try { cs = datasource.getConnection().prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)"); cs.setString(1, lastBackupURL); cs.execute(); } catch (SQLException e) { LOGGER.error("Cannot perform database backup!", e); return; } finally { try { cs.close(); } catch (SQLException e) { LOGGER.error("Error closing backup connection ", e); return; } } File backupURLFile = new File(lastBackupURL); // zip the contents and delete the dir ZipUtil.pack(backupURLFile, new File(lastBackupURL + ARCHIVE_SUFFIX)); // delete the backup directory that we just zipped try { FileUtils.deleteDirectory(backupURLFile); } catch (IOException e) { LOGGER.error("Cannot delete temporary backup directory", e); } LOGGER.info("Backed up database to " + lastBackupURL + ARCHIVE_SUFFIX); }
From source file:com.mimp.hibernate.HiberMail.java
public ArrayList<Object> usuario2(String user, String pass) { org.hibernate.Session session = sessionFactory.getCurrentSession(); final String usuario = user; final String password = pass; Work work = new Work() { @Override/*from ww w .j a v a 2 s . com*/ public void execute(Connection connection) throws SQLException { String query = "{call CONTRASENA(?, ?, ?, ?)}"; CallableStatement statement = connection.prepareCall(query); statement.setString(1, usuario); statement.setString(2, password); statement.registerOutParameter(3, java.sql.Types.VARCHAR); statement.registerOutParameter(4, java.sql.Types.VARCHAR); statement.execute(); String correo = statement.getString(3); String mensaje = statement.getString(4); temp.add(0, correo); temp.add(1, mensaje); statement.close(); } }; session.doWork(work); return temp; }
From source file:com.mobilewallet.common.dao.RegisterDAO.java
public Object[] registerUser(String email, String fname, String lname, String dob, String gender, String pwd, String imei, String accounts, String country, String handsetModel, String androidVer, String emulator, String gcmId, String androidId, String refCode, String ip, String fbId) { Object[] obj = null;// ww w .j a va2 s . c o m Connection con = null; CallableStatement cstmt = null; try { con = ds.getConnection(); cstmt = con.prepareCall("{call REGISTER_USER(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); cstmt.setString(1, email); cstmt.setString(2, fname); cstmt.setString(3, lname); cstmt.setString(4, dob); cstmt.setString(5, gender); cstmt.setString(6, pwd); cstmt.setString(7, imei); cstmt.setString(8, accounts); cstmt.setString(9, country); cstmt.setString(10, handsetModel); cstmt.setString(11, androidVer); cstmt.setString(12, emulator); cstmt.setString(13, gcmId); cstmt.setString(14, androidId); cstmt.setString(15, refCode); cstmt.setString(16, ip); cstmt.setString(17, fbId); cstmt.registerOutParameter(18, java.sql.Types.INTEGER); cstmt.registerOutParameter(19, java.sql.Types.VARCHAR); cstmt.registerOutParameter(20, java.sql.Types.INTEGER); cstmt.registerOutParameter(21, java.sql.Types.INTEGER); cstmt.execute(); obj = new Object[4]; obj[0] = cstmt.getInt(18);//rvalue obj[1] = cstmt.getString(19);//user ref code obj[2] = cstmt.getFloat(20);//balance obj[3] = cstmt.getLong(21);//user id } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (con != null) { con.close(); } } catch (Exception ex) { } } return obj; }