List of usage examples for java.sql CallableStatement execute
boolean execute() throws SQLException;
PreparedStatement
object, which may be any kind of SQL statement. From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ??//from w ww . j a v a2 s .c o m */ public static int checkEntExists(String entCode) { int retCode = -1; Connection conn = null; CallableStatement proc = null; String call = "{call Pro_CheckEntExists(?,?)}"; try { conn = DBPool.ds.getConnection(); proc = conn.prepareCall(call); System.out.println("entcode" + entCode); proc.setString(1, entCode); proc.registerOutParameter(2, Types.INTEGER); proc.execute(); retCode = proc.getInt(2); System.out.println("retcode" + retCode); } catch (SQLException e) { // TODO Auto-generated catch block log.error("N39", e); } catch (Exception e) { log.error("N40", e); } finally { try { if (proc != null) { proc.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block log.error("N41", e); } } return retCode; }
From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ???????//from w ww. ja v a 2s . c om */ public static int saveDeclProduct(String declNo, String entProductCode, String baseCode, String goodsNo) { int retCode = -1; Connection conn = null; CallableStatement proc = null; ResultSet rs = null; String call = "{call Pro_SaveDeclProduct(?,?,?,?,?)}"; try { conn = DBPool.ds.getConnection(); proc = conn.prepareCall(call); proc.setString(1, declNo); proc.setString(2, entProductCode); proc.setString(3, baseCode); proc.setString(4, goodsNo); proc.registerOutParameter(5, Types.INTEGER); proc.execute(); retCode = proc.getInt(5); } catch (SQLException e) { // TODO Auto-generated catch block log.error("N54", e); } catch (Exception e) { log.error("N55", e); } finally { try { if (rs != null) { rs.close(); } if (proc != null) { proc.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block log.error("N56", e); } } return retCode; }
From source file:genepi.db.JdbcDataAccessObject.java
public boolean callProcedure(String sql, Object[] params) throws SQLException { Connection connection = null; try {//from ww w.j a va2s. c om connection = database.getDataSource().getConnection(); CallableStatement cstmt = connection.prepareCall(sql); runner.fillStatement(cstmt, params); boolean state = cstmt.execute(); cstmt.close(); connection.close(); return state; } catch (SQLException e) { throw e; } finally { connection.close(); } }
From source file:com.taobao.diamond.server.service.HangingModePersistService.java
/** * Returns a List(Map) collection.//from ww w . ja va 2 s . co m * * @param cs * object that can create a CallableStatement given a Connection * @return resultsList a result object returned by the action, or null */ public Object doInCallableStatement(CallableStatement cs) { try { // cs.setInt(1,1000); cs.execute(); } catch (SQLException e) { throw new RuntimeException("doInCallableStatement method error : SQLException " + e.getMessage()); } return null; }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyOnlineSyncJob.java
private void executeProcedure(final String procedure) { jdbcOperations.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection con) throws SQLException { log.trace("Calling {} procedure", procedure); return con.prepareCall(procedure); }/*from w w w . j a v a 2s .com*/ }, new CallableStatementCallback<Object>() { public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.execute(); return null; } }); }
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 {/* w w w .ja v a 2 s .c o 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/*ww w. ja v a2 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:org.marccarre.spring.db.testing.FooDao.java
public List<Foo> getByIdCallableStatement(int id) { final int fooId = id; return jdbcTemplate.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection con) throws SQLException { CallableStatement cs = con.prepareCall("{call GetFoosById(?)}"); cs.setInt(1, fooId);/* www. j a v a2 s .c o m*/ return cs; } }, new CallableStatementCallback<List<Foo>>() { public List<Foo> doInCallableStatement(CallableStatement cs) throws SQLException { cs.execute(); List<Foo> foos = new ArrayList<Foo>(); if (cs.getMoreResults()) { ResultSet rs = cs.getResultSet(); FooRowMapper mapper = new FooRowMapper(); int rowIndex = 0; while (rs.next()) { foos.add(mapper.mapRow(rs, rowIndex)); rowIndex++; } } return foos; } }); }
From source file:com.jaspersoft.jrx.query.PlSqlQueryExecuter.java
public JRDataSource createDatasource() throws JRException { JRDataSource dataSource = null;// w w w. j a va 2s . c o m createStatement(); if (statement != null) { try { Integer reportMaxCount = (Integer) getParameterValue(JRParameter.REPORT_MAX_COUNT); if (reportMaxCount != null) { statement.setMaxRows(reportMaxCount.intValue()); } if (isStoredProcedure) { CallableStatement cstmt = (CallableStatement) statement; cstmt.execute(); if (cursorParameter > 0) { resultSet = (java.sql.ResultSet) cstmt.getObject(cursorParameter); } } else { resultSet = statement.executeQuery(); } dataSource = new JRResultSetDataSource(resultSet); } catch (SQLException e) { throw new JRException("Error executing SQL statement for : " + dataset.getName(), e); } } return dataSource; }
From source file:com.mobilewallet.common.dao.RegisterDAO.java
public void updateGCM(String userId, String gcmId) { Connection con = null;// w ww.ja v a 2 s . c o m 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) { } } }