List of usage examples for java.sql CallableStatement registerOutParameter
default void registerOutParameter(String parameterName, SQLType sqlType) throws SQLException
parameterName
to the JDBC type sqlType . From source file:com.mobilewallet.users.dao.NotificationsDAO.java
public int updateNotification(long userId, String status, String type) { int updated = 0; Connection connection = null; CallableStatement cstmt = null; try {// ww w . j a v a 2s . c o m connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_update_push_notification(?,?,?,?)}"); cstmt.setLong(1, userId); cstmt.setString(2, status); cstmt.setString(3, type); cstmt.registerOutParameter(4, java.sql.Types.INTEGER); cstmt.execute(); updated = cstmt.getInt(4); } catch (Exception ex) { } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return updated; }
From source file:ips1ap101.lib.core.db.util.DB.java
public static CallableStatement prepareCall(Connection connection, String sql, Object[] args, EnumTipoResultadoSQL resultType, EnumTipoDatoSQL dataType) { CallableStatement callableStatement; if (connection != null && sql != null) { try {/* w w w . ja v a 2s . co m*/ callableStatement = connection.prepareCall(sql); int n = args == null ? 0 : args.length; if (n > 0) { for (int i = 0; i < n; i++) { if (args[i] == null) { // callableStatement.setNull(i + 1, java.sql.Types.OTHER); callableStatement.setNull(i + 1, java.sql.Types.NULL); } else if (args[i] instanceof EnumTipoDatoSQL) { EnumTipoDatoSQL tipoDatoSQL = (EnumTipoDatoSQL) args[i]; callableStatement.setNull(i + 1, tipoDatoSQL.intValue()); } else { callableStatement.setObject(i + 1, args[i]); } } } if (EnumTipoResultadoSQL.SIMPLE.equals(resultType) && dataType != null) { callableStatement.registerOutParameter(n + 1, dataType.intValue()); } return callableStatement; } catch (SQLException ex) { Bitacora.logFatal(ex); } } return null; }
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/*www. j av a 2 s . co m*/ 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.aw.core.dao.DAOSql.java
/** * Call example//w w w.ja va2 s . c om * 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.LoginDAO.java
public String getUserPassword(String email, String ip) { Connection connection = null; CallableStatement cstmt = null; String password = null;//from www .j a v a 2s . c o m try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call fp_forgot_password(?,?,?)}"); cstmt.setString(1, email); cstmt.setString(2, ip); cstmt.registerOutParameter(3, java.sql.Types.VARCHAR); cstmt.execute(); password = cstmt.getString(3); } 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 password; }
From source file:com.aw.core.dao.DAOSql.java
protected void dbmsOutputPrint(Connection conn, StringBuffer buf) throws java.sql.SQLException { String getLineSql = "begin dbms_output.get_line(?,?); end;"; CallableStatement stmt = conn.prepareCall(getLineSql); boolean hasMore = true; stmt.registerOutParameter(1, Types.VARCHAR); stmt.registerOutParameter(2, Types.INTEGER); while (hasMore) { boolean status = stmt.execute(); hasMore = (stmt.getInt(2) == 0); if (hasMore) { buf.append(stmt.getString(1)).append("\n"); }//from w w w . j a v a 2 s . c o m } stmt.close(); }
From source file:com.mobilewallet.common.dao.ForgotPasswordDAO.java
public int checkResetLink(String uuid, String userId, String ip) { Connection connection = null; CallableStatement cstmt = null; int rvalue = -1; try {/*from w w w . j ava2s . co m*/ connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_check_reset_link(?,?,?,?)}"); cstmt.setString(1, userId); cstmt.setString(2, uuid); cstmt.setString(3, ip); cstmt.registerOutParameter(4, java.sql.Types.INTEGER); cstmt.execute(); rvalue = cstmt.getInt(4); log.info("Rvalue Check ResetLink : " + rvalue); } 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 rvalue; }
From source file:com.oracle.tutorial.jdbc.StoredProcedureMySQLSample.java
public void runStoredProcedures(String coffeeNameArg, float maximumPercentageArg, float newPriceArg) throws SQLException { CallableStatement cs = null; try {// w w w. j a v a2 s . co m System.out.println("\nCalling the procedure GET_SUPPLIER_OF_COFFEE"); cs = this.con.prepareCall("{call GET_SUPPLIER_OF_COFFEE(?, ?)}"); cs.setString(1, coffeeNameArg); cs.registerOutParameter(2, Types.VARCHAR); cs.executeQuery(); String supplierName = cs.getString(2); if (supplierName != null) { System.out.println("\nSupplier of the coffee " + coffeeNameArg + ": " + supplierName); } else { System.out.println("\nUnable to find the coffee " + coffeeNameArg); } System.out.println("\nCalling the procedure SHOW_SUPPLIERS"); cs = this.con.prepareCall("{call SHOW_SUPPLIERS}"); ResultSet rs = cs.executeQuery(); while (rs.next()) { String supplier = rs.getString("SUP_NAME"); String coffee = rs.getString("COF_NAME"); System.out.println(supplier + ": " + coffee); } System.out.println("\nContents of COFFEES table before calling RAISE_PRICE:"); CoffeesTable.viewTable(this.con); System.out.println("\nCalling the procedure RAISE_PRICE"); cs = this.con.prepareCall("{call RAISE_PRICE(?,?,?)}"); cs.setString(1, coffeeNameArg); cs.setFloat(2, maximumPercentageArg); cs.registerOutParameter(3, Types.NUMERIC); cs.setFloat(3, newPriceArg); cs.execute(); System.out.println("\nValue of newPrice after calling RAISE_PRICE: " + cs.getFloat(3)); System.out.println("\nContents of COFFEES table after calling RAISE_PRICE:"); CoffeesTable.viewTable(this.con); } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (cs != null) { cs.close(); } } }
From source file:de.unibremen.informatik.tdki.combo.data.DBLayout.java
private boolean projectExists(String project) { CallableStatement callableStatement = null; boolean projectExists = false; try {/* ww w .j a va 2 s . c om*/ callableStatement = connection.prepareCall("CALL combo_project_exists('" + project + "',?)"); callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); callableStatement.executeUpdate(); projectExists = (callableStatement.getInt(1) != 0); } catch (SQLException ex) { throw new RuntimeException(ex); } finally { DbUtils.closeQuietly(callableStatement); } return projectExists; }
From source file:de.unibremen.informatik.tdki.combo.data.DBLayout.java
/** * * @param project/*w w w. j a v a2 s . c om*/ * @return true if the project already exists */ public boolean createProject(String project) { CallableStatement callableStatement = null; boolean projectExists = false; try { callableStatement = connection.prepareCall("CALL combo_create_project('" + project + "',?)"); callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); callableStatement.executeUpdate(); projectExists = (callableStatement.getInt(1) != 0); } catch (SQLException ex) { throw new RuntimeException(ex); } finally { DbUtils.closeQuietly(callableStatement); } return projectExists; }