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.mobilewallet.admin.dao.QuestionDAO.java
public int approveQuestion(long userId, long q_id, String is_admin_approved) { Connection connection = null; CallableStatement pstmt = null; ResultSet rs = null;//from ww w .ja va 2 s . c om int approved = 0; try { connection = dataSource.getConnection(); pstmt = connection.prepareCall("{call approve_question(?,?,?,?)}"); pstmt.setLong(1, userId); pstmt.setLong(2, q_id); pstmt.setString(3, is_admin_approved); pstmt.registerOutParameter(4, java.sql.Types.INTEGER); pstmt.execute(); approved = pstmt.getInt(4); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (pstmt != null) { pstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return approved; }
From source file:com.mobilewallet.common.dao.ForgotPasswordDAO.java
public Object[] getResetPasswordLink(String email, String uuid, String ip) { Connection connection = null; CallableStatement cstmt = null; Object[] obj = null;/*from w w w . j a v a2 s. c om*/ int rvalue = -1; long userId = 0; try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_forgot_pwd_reset_link(?,?,?,?,?)}"); cstmt.setString(1, email); cstmt.setString(2, uuid); cstmt.setString(3, ip); cstmt.registerOutParameter(4, java.sql.Types.INTEGER); cstmt.registerOutParameter(5, java.sql.Types.INTEGER); cstmt.execute(); rvalue = cstmt.getInt(4); userId = cstmt.getLong(5); obj = new Object[2]; obj[0] = rvalue; obj[1] = userId; } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return obj; }
From source file:com.nextep.designer.sqlgen.oracle.debug.ctrl.DebugMethod.java
@Override public Object invokeMethod(Object... arg) { IConnection conn = (IConnection) arg[0]; CallableStatement stmt = null; Thread debuggedThread = null; try {//from w w w . ja v a 2s . c o m // Initializing our target connection targetConn = CorePlugin.getConnectionService().connect(conn); // stmt = targetConn.prepareCall("ALTER SESSION SET PLSQL_DEBUG=TRUE"); //$NON-NLS-1$ try { stmt.execute(); } finally { CaptureHelper.safeClose(null, stmt); } stmt = targetConn.prepareCall("{ ? = CALL DBMS_DEBUG.INITIALIZE() }"); //$NON-NLS-1$ try { stmt.registerOutParameter(1, Types.VARCHAR); stmt.execute(); debugSessionID = stmt.getString(1); } catch (SQLException e) { throw new ErrorException(e); } finally { CaptureHelper.safeClose(null, stmt); } // Switching to debug mode stmt = targetConn.prepareCall("{ CALL DBMS_DEBUG.DEBUG_ON() }"); //$NON-NLS-1$ try { stmt.execute(); } finally { CaptureHelper.safeClose(null, stmt); } // Starting our target code debuggedThread = new Thread(new TargetRunnable(targetConn)); debuggedThread.start(); // Now that we have our ID, we initialize debug connection debugConn = CorePlugin.getConnectionService().connect(conn); // new Thread(new DebugRunnable(debugConn,debugSessionID)).start(); stmt = debugConn.prepareCall("{ CALL DBMS_DEBUG.ATTACH_SESSION(?) }"); //$NON-NLS-1$ try { stmt.setString(1, debugSessionID); stmt.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { CaptureHelper.safeClose(null, stmt); } stmt = debugConn.prepareCall("{ ? = CALL DBMS_DEBUG.SYNCHRONIZE(?,0) }"); //$NON-NLS-1$ try { stmt.registerOutParameter(1, Types.INTEGER); stmt.registerOutParameter(2, OracleTypes.OTHER, "DBMS_DEBUG.RUNTIME_INFO"); //$NON-NLS-1$ stmt.execute(); Object o = stmt.getObject(2); if (o != null) { } } catch (SQLException e) { e.printStackTrace(); } finally { CaptureHelper.safeClose(null, stmt); } // // Setting breakpoints // stmt = // debugConn.prepareCall("{ call adp_debug.set_breakpoint(p_line=>?, p_name=>?, p_body=>true) }"); // try { // for(IBreakpoint bp : SQLEditorUIServices.getInstance().getBreakpoints()) { // stmt.setInt(1, bp.getLine()); // stmt.setString(2,bp.getTarget().getName()); // stmt.execute(); // } // } catch( Exception e) { // e.printStackTrace(); // } finally { // stmt.close(); // } stmt = debugConn.prepareCall("{ ? = CALL DBMS_DEBUG.CONTINUE(?,0,46) }"); //$NON-NLS-1$ stmt.registerOutParameter(1, Types.INTEGER); stmt.registerOutParameter(2, OracleTypes.OTHER, "DBMS_DEBUG.RUNTIME_INFO"); //$NON-NLS-1$ try { stmt.execute(); Struct struct = (Struct) stmt.getObject(2); Object[] attrs = struct.getAttributes(); int line = (Integer) attrs[0]; int terminated = (Integer) attrs[1]; int breakpoint = (Integer) attrs[2]; LOGGER.debug( "Continued to line " + line + ", terminated=" + terminated + ", breakpoint=" + breakpoint); } catch (SQLException e) { e.printStackTrace(); } finally { CaptureHelper.safeClose(null, stmt); } } catch (SQLException e) { if (debuggedThread != null) { debuggedThread.interrupt(); } throw new ErrorException(e); } finally { try { if (debugConn != null) { debugConn.close(); } } catch (SQLException e) { throw new ErrorException("Unable to properly close connection: " + e.getMessage(), e); } } return null; }
From source file:com.bstek.dorado.core.store.H2BaseStore.java
protected void prepareNamespace() throws Exception { Class.forName(driverClassName); Connection conn = DriverManager.getConnection(getConnectionUrl(), username, password); try {//from w w w. j a va 2 s . c o m int storeVersion = 0; CallableStatement prepareCall = conn.prepareCall("SELECT @storeVersion"); ResultSet resultSet = prepareCall.executeQuery(); try { if (resultSet.first()) { storeVersion = resultSet.getInt("@storeVersion"); } } finally { resultSet.close(); prepareCall.close(); } if (storeVersion < version) { logger.info("Initializing store \"" + namespace + "\"."); prepareCall = conn.prepareCall("SET @storeVersion = " + version); try { prepareCall.execute(); } finally { prepareCall.close(); } initNamespace(conn); } } finally { conn.close(); } }
From source file:com.aw.core.dao.DAOSql.java
/** * Call example//from ww w. j a v a 2 s .c o m * execSqlFunction(sqlUpdSqldoActor, Types.NUMERIC, new Object[]{"dss"}) */ public boolean execSqlProcedure(String sql, Object[] sqlParams) { try { CallableStatement cstmt = getHibernateConnection().prepareCall(sql); if (sqlParams != null) for (int i = 0; i < sqlParams.length; i++) { cstmt.setObject(i + 1, sqlParams[i]); } logger.debug("SQL Exec:" + buildSQL(sql, sqlParams)); boolean result = cstmt.execute(); cstmt.close(); return result; } catch (SQLException e) { logger.error("SQL:" + buildSQL(sql, sqlParams), e); throw AWBusinessException.wrapUnhandledException(logger, e); } }
From source file:com.jfootball.dao.hibernate.PlayerDaoImpl.java
public void endSeasonJob() { logger.info("Execute endSeason job"); Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory(); try {/*w w w . j av a 2 s.c o m*/ Connection conn = sessionFactory.getConnectionProvider().getConnection(); CallableStatement cstmt = conn.prepareCall("{ call endSeasonBatch(?) }"); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(new Date(System.currentTimeMillis())); int year = gc.get(Calendar.YEAR); cstmt.setString("param_year", "30/06/" + year); // current year. cstmt.execute(); logger.info("EndSeason job executed"); } catch (SQLException e) { logger.error(e); } logger.info("EndSeason job finished"); }
From source file:com.aw.core.dao.DAOSql.java
/** * Call example/*w ww . ja v a 2 s . c o m*/ * execSqlFunction(sqlUpdSqldoActor, Types.NUMERIC, new Object[]{"dss"}) */ public Object execSqlFunction(String sql, int returnSqlType, Object[] sqlParams) { try { CallableStatement cstmt = getHibernateConnection().prepareCall(sql); cstmt.registerOutParameter(1, returnSqlType); if (sqlParams != null) for (int i = 0; i < sqlParams.length; i++) { cstmt.setObject(i + 2, sqlParams[i]); } logger.debug("SQL Exec:" + buildSQL(sql, sqlParams)); cstmt.execute(); Object returnValue = cstmt.getObject(1); cstmt.close(); return returnValue; } catch (SQLException e) { logger.error("SQL:" + buildSQL(sql, sqlParams), e); throw AWBusinessException.wrapUnhandledException(logger, e); } }
From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java
public Object[] addReferralIncetive(long userId, String refCode, String imei, String ip) { int added = 0; Connection connection = null; CallableStatement cstmt = null; String gcmId = null;/* w w w .j a v a2s . c o m*/ Object[] obj = null; try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call ADD_REFERRAL_CREDIT(?,?,?,?,?,?,?)}"); cstmt.setLong(1, userId); cstmt.setString(2, refCode); cstmt.setString(3, imei); cstmt.setString(4, ip); cstmt.registerOutParameter(5, java.sql.Types.INTEGER); cstmt.registerOutParameter(6, java.sql.Types.VARCHAR); cstmt.registerOutParameter(7, java.sql.Types.VARCHAR); cstmt.execute(); added = cstmt.getInt(5); gcmId = cstmt.getString(6); obj = new Object[3]; obj[0] = added; obj[1] = gcmId; obj[2] = cstmt.getString(7); } catch (Exception ex) { ex.printStackTrace(); log.error("Error in add referral incentive dao : " + ex.getMessage() + ", USER ID " + userId + ", refCode : " + refCode + ", imei : " + imei + ", IP : " + ip); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return obj; }
From source file:de.awtools.grooocle.varray.VarrayTest.java
@Test @Ignore//from w w w . ja v a2s .c o m public void testOraclesVarrayWithPackage() throws Exception { CallableStatement cs = null; try { String arrayElements[] = { "Test3", "Test4", "Test5" }; // int n = OracleTypeCOLLECTION.TYPE_PLSQL_INDEX_TABLE; // ArrayDescriptor desc = ArrayDescriptor.createDescriptor(); ArrayDescriptor desc = ArrayDescriptor.createDescriptor("CP_TEST.t_ROWNUMBER", conn); ARRAY newArray = new ARRAY(desc, conn, arrayElements); String spCall = "{ call CP_TEST.call_me(?, ?) }"; cs = conn.prepareCall(spCall); cs.setArray(1, newArray); cs.registerOutParameter(2, java.sql.Types.INTEGER); cs.execute(); assertEquals(3, cs.getInt(2)); } finally { if (cs != null) { cs.close(); } } }
From source file:com.mobilewallet.users.dao.UserQuestionsDAO.java
public int submitQuestion(long userId, String question, String answerA, String answerB, String answerC, String answerD, String answer) { Connection connection = null; CallableStatement pstmt = null; ResultSet rs = null;/*from ww w . j a va 2 s . c o m*/ int submitted = 0; try { connection = dataSource.getConnection(); pstmt = connection.prepareCall("{call submit_question(?,?,?,?,?,?,?,?)}"); pstmt.setLong(1, userId); pstmt.setString(2, question); pstmt.setString(3, answerA); pstmt.setString(4, answerB); pstmt.setString(5, answerC); pstmt.setString(6, answerD); pstmt.setString(7, answer); pstmt.registerOutParameter(8, java.sql.Types.INTEGER); pstmt.execute(); submitted = pstmt.getInt(8); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (pstmt != null) { pstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return submitted; }