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:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public String signin(final int userUid) { Connection conn = null;//from w w w.java 2 s. c o m CallableStatement stmt = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_SIGNIN (?,?)}"); stmt.setInt(1, userUid); stmt.registerOutParameter(2, Types.VARCHAR); stmt.execute(); return stmt.getString(2); } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); } finally { DbUtils.closeQuietly(conn, stmt, null); } return null; }
From source file:com.mimp.hibernate.HiberNna.java
public String get_Last_numero_expediente() { Session session = sessionFactory.getCurrentSession(); Work work;/*from www . j av a 2 s . c o m*/ work = new Work() { @Override public void execute(Connection connection) throws SQLException { numero_last = null; ResultSet temp_numero; String hql = "{call HN_GET_LAST_EXPEDIENTE_NNA(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp_numero = (ResultSet) statement.getObject(1); while (temp_numero.next()) { numero_last = temp_numero.getString(2); } temp_numero.close(); statement.close(); } }; session.doWork(work); return numero_last; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseTenantTable.java
public long nextTSecGroupMemberIdGen(CFSecurityAuthorization Authorization, CFSecurityTenantPKey PKey) { final String S_ProcName = "nextTSecGroupMemberIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }//from w ww. ja v a2s . c om Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupMemberIdGen = null; try { String sql = "{ call sp_next_tsecgroupmemberidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupMemberIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupMemberIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupMemberIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupMemberIdGen.execute(); long nextId = stmtSelectNextTSecGroupMemberIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupMemberIdGen != null) { try { stmtSelectNextTSecGroupMemberIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupMemberIdGen = null; } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseTenantTable.java
public long nextTSecGroupIncludeIdGen(CFSecurityAuthorization Authorization, CFSecurityTenantPKey PKey) { final String S_ProcName = "nextTSecGroupIncludeIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/* w ww . j a va 2 s . c om*/ Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupIncludeIdGen = null; try { String sql = "{ call sp_next_tsecgroupincludeidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupIncludeIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupIncludeIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupIncludeIdGen.execute(); long nextId = stmtSelectNextTSecGroupIncludeIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupIncludeIdGen != null) { try { stmtSelectNextTSecGroupIncludeIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupIncludeIdGen = null; } } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java
/** * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#validateUserAccount(java.lang.String, java.lang.String) */// w w w.j ava 2 s.c o m public synchronized boolean validateUserAccount(final String userId, final String userGuid) throws UserManagementException { final String methodName = SQLUserManager.CNAME + "#validateUserAccount(final String userId, final String userGuid) throws UserManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", userGuid); } boolean isValid = false; Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; try { sqlConn = SQLUserManager.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{ CALL getUserByAttribute(?, ?) }"); stmt.setString(1, userId); stmt.setInt(2, 0); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.executeQuery(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); while (resultSet.next()) { if ((StringUtils.equals(resultSet.getString(1), userGuid)) || (StringUtils.equals(resultSet.getString(2), userId))) { resultSet.close(); stmt.close(); sqlConn.close(); throw new UserManagementException( "A user currently exists with the provided information."); } } } } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } finally { try { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new UserManagementException(sqx.getMessage(), sqx); } } return isValid; }
From source file:lib.JdbcTemplate.java
@Override public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters) throws DataAccessException { final List<SqlParameter> updateCountParameters = new ArrayList<SqlParameter>(); final List<SqlParameter> resultSetParameters = new ArrayList<SqlParameter>(); final List<SqlParameter> callParameters = new ArrayList<SqlParameter>(); for (SqlParameter parameter : declaredParameters) { if (parameter.isResultsParameter()) { if (parameter instanceof SqlReturnResultSet) { resultSetParameters.add(parameter); } else { updateCountParameters.add(parameter); }/*from w w w. ja v a 2 s. c om*/ } else { callParameters.add(parameter); } } return execute(csc, new CallableStatementCallback<Map<String, Object>>() { @Override public Map<String, Object> doInCallableStatement(CallableStatement cs) throws SQLException { boolean retVal = cs.execute(); int updateCount = cs.getUpdateCount(); if (logger.isDebugEnabled()) { logger.debug("CallableStatement.execute() returned '" + retVal + "'"); logger.debug("CallableStatement.getUpdateCount() returned " + updateCount); } Map<String, Object> returnedResults = createResultsMap(); if (retVal || updateCount != -1) { returnedResults.putAll( extractReturnedResults(cs, updateCountParameters, resultSetParameters, updateCount)); } returnedResults.putAll(extractOutputParameters(cs, callParameters)); return returnedResults; } }); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseTenantTable.java
public long nextTSecGroupMemberIdGen(CFAstAuthorization Authorization, CFAstTenantPKey PKey) { final String S_ProcName = "nextTSecGroupMemberIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }//from w w w .j a v a 2 s . c o m Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupMemberIdGen = null; try { String sql = "{ call sp_next_tsecgroupmemberidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupMemberIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupMemberIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupMemberIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupMemberIdGen.execute(); long nextId = stmtSelectNextTSecGroupMemberIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupMemberIdGen != null) { try { stmtSelectNextTSecGroupMemberIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupMemberIdGen = null; } } }
From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#insertMessage(List) *///from ww w .j a v a2 s . c o m public synchronized boolean insertMessage(final List<Object> messageList) throws SQLException { final String methodName = IWebMessagingDAO.CNAME + "#insertMessage(final List<Object> messageList) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("messageList: {}", messageList); } Connection sqlConn = null; CallableStatement stmt = null; boolean isComplete = false; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL submitSvcMessage(?, ?, ?, ?, ?, ?, ?, ?)}"); stmt.setString(1, (String) messageList.get(0)); // message id stmt.setString(2, (String) messageList.get(1)); // message title stmt.setString(3, (String) messageList.get(2)); // message text stmt.setString(4, (String) messageList.get(3)); // author email stmt.setBoolean(5, (Boolean) messageList.get(4)); // is active stmt.setBoolean(6, (Boolean) messageList.get(5)); // is alert stmt.setBoolean(7, (Boolean) messageList.get(6)); // does expire stmt.setLong(8, (messageList.get(7) == null) ? 0 : (Long) messageList.get(7)); // expiry date isComplete = (!(stmt.execute())); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return isComplete; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseTenantTable.java
public long nextTSecGroupIncludeIdGen(CFAstAuthorization Authorization, CFAstTenantPKey PKey) { final String S_ProcName = "nextTSecGroupIncludeIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }// www . j a v a 2 s . c o m Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupIncludeIdGen = null; try { String sql = "{ call sp_next_tsecgroupincludeidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupIncludeIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupIncludeIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupIncludeIdGen.execute(); long nextId = stmtSelectNextTSecGroupIncludeIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupIncludeIdGen != null) { try { stmtSelectNextTSecGroupIncludeIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupIncludeIdGen = null; } } }
From source file:com.mimp.hibernate.HiberNna.java
public ArrayList<ExpedienteNna> listaExpNna() { Session session = sessionFactory.getCurrentSession(); final ArrayList<ExpedienteNna> allExpNna = new ArrayList(); Work work = new Work() { @Override//from www . j a v a 2 s . c o m public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HN_GET_EXPEDIENTE_NNA(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp = (ResultSet) statement.getObject(1); while (temp.next()) { expnna = new ExpedienteNna(); expnna.setIdexpedienteNna(temp.getShort(1)); expnna.setNumero(temp.getString(4)); expnna.setFechaIngreso(temp.getDate(5)); expnna.setHt(temp.getString(6)); expnna.setNExpTutelar(temp.getString(7)); expnna.setProcTutelar(temp.getString(8)); expnna.setFichaIntegral(temp.getShort(9)); expnna.setComentarios(temp.getString(10)); expnna.setRespLegalNombre(temp.getString(11)); expnna.setRespLegalP(temp.getString(12)); expnna.setRespLegalM(temp.getString(13)); expnna.setRespPsicosocialNombre(temp.getString(14)); expnna.setRespPiscosocialP(temp.getString(15)); expnna.setRespPsicosocialM(temp.getString(16)); expnna.setEstado(temp.getString(17)); expnna.setFechaEstado(temp.getDate(18)); expnna.setAdoptable(temp.getShort(19)); expnna.setFechaResolCons(temp.getDate(20)); expnna.setNacional(temp.getShort(21)); expnna.setDiagnostico(temp.getString(22)); expnna.setCodigoReferencia(temp.getString(23)); expnna.setNActual(temp.getString(24)); expnna.setApellidopActual(temp.getString(25)); expnna.setApellidomActual(temp.getString(26)); expnna.setObservaciones(temp.getString(27)); expnna.setFechaInvTutelar(temp.getDate(28)); allExpNna.add(expnna); } temp.close(); statement.close(); } }; session.doWork(work); return allExpNna; }