Example usage for java.sql CallableStatement getString

List of usage examples for java.sql CallableStatement getString

Introduction

In this page you can find the example usage for java.sql CallableStatement getString.

Prototype

String getString(String parameterName) throws SQLException;

Source Link

Document

Retrieves the value of a JDBC CHAR, VARCHAR, or LONGVARCHAR parameter as a String in the Java programming language.

Usage

From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java

public String showInvitationStrig(long userId) {
    Connection connection = null;
    CallableStatement cstmt = null;
    String show = null;//from w w  w. ja v a  2  s. c  o m

    try {
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call wp_show_invitation(?,?)}");
        cstmt.setLong(1, userId);
        cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);

        cstmt.execute();

        show = cstmt.getString(2);

    } 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 show;
}

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;/* ww  w.j  av  a 2  s .  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:edu.harvard.i2b2.crc.dao.setfinder.QueryInstanceSpringDao.java

private void getSQLServerProcedureError(String serverType, CallableStatement callStmt, int outParamIndex)
        throws SQLException, I2B2Exception {

    if (serverType.equalsIgnoreCase(DataSourceLookupDAOFactory.SQLSERVER)) {
        String errorMsg = callStmt.getString(outParamIndex);
        if (errorMsg != null) {
            log.debug("error codde" + errorMsg);
            throw new I2B2Exception("Error from stored procedure [" + errorMsg + "]");
        }//from   w w  w  .j a  v a  2s .c om
    }
}

From source file:com.oracle.tutorial.jdbc.StoredProcedureMySQLSample.java

public void runStoredProcedures(String coffeeNameArg, float maximumPercentageArg, float newPriceArg)
        throws SQLException {
    CallableStatement cs = null;

    try {/*www  . jav  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:org.squale.welcom.outils.jdbc.WJdbc.java

/**
 * Crype la chaine via l'appel  la Focntion decrypte_FCT
 * //w ww  .ja  v  a 2s  .co m
 * @param text Texte a dcript
 * @return Chaine dcrypt
 * @throws SQLException Erreur SQL
 */
public String crypte(final String text) throws SQLException {
    CallableStatement cs = null;

    try {
        cs = conn.prepareCall("{? = call crypte_FCT(?)}");
        cs.registerOutParameter(1, java.sql.Types.VARCHAR);
        cs.setString(2, text);
        cs.executeUpdate();

        return cs.getString(1);
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}

From source file:org.squale.welcom.outils.jdbc.WJdbc.java

/**
 * DeCrype la chaine via l'appel  la Focntion decrypte_FCT
 * //  w w w  .j av a  2 s. c o  m
 * @param text Texte a dcript
 * @return Chaine dcrypt
 * @throws SQLException Erreur SQL
 */
public String decrypte(final String text) throws SQLException {
    CallableStatement cs = null;

    try {
        cs = conn.prepareCall("{? = call decrypte_FCT(?)}");
        cs.registerOutParameter(1, java.sql.Types.VARCHAR);
        cs.setString(2, text);
        cs.executeUpdate();

        return cs.getString(1);
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}

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   w w  w .j  a  v a 2  s. c  o  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:org.kuali.coeus.common.impl.krms.StoredFunctionDao.java

public String executeFunction(final String functionName, final List<Object> paramValues) {

    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    String result = jdbcTemplate.execute(new CallableStatementCreator() {
        @Override//from w w  w . j a  v a  2  s .  c om
        public CallableStatement createCallableStatement(Connection con) throws SQLException {
            String paramSyntaxString = "";
            int paramCount = paramValues.size();
            for (int i = 0; i < paramCount; i++) {
                if (i == 0)
                    paramSyntaxString += "(?";
                else if (i == paramCount - 1)
                    paramSyntaxString += ",?)";
                else
                    paramSyntaxString += ",?";
            }
            if (paramCount == 1)
                paramSyntaxString += ")";
            CallableStatement cs = con.prepareCall("{ ? = call " + functionName + paramSyntaxString + "}");
            cs.registerOutParameter(1, Types.VARCHAR);
            for (int i = 0; i < paramValues.size(); i++) {
                cs.setObject(i + 2, paramValues.get(i));
            }
            return cs;
        }
    }, new CallableStatementCallback<String>() {
        @Override
        public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
            cs.execute();
            String result = cs.getString(1);
            return result;
        }

    });
    LOG.debug(functionName + " result: " + result);
    return result;
}

From source file:com.oracle.tutorial.jdbc.StoredProcedureJavaDBSample.java

public void runStoredProcedures(String coffeeNameArg, double maximumPercentageArg, double newPriceArg)
        throws SQLException {
    CallableStatement cs = null;

    try {/*from  w  w  w  .  j a va  2 s  . com*/

        System.out.println("\nCalling the stored procedure GET_SUPPLIER_OF_COFFEE");
        cs = this.con.prepareCall("{call GET_SUPPLIER_OF_COFFEE(?, ?)}");
        cs.setString(1, coffeeNameArg);
        cs.registerOutParameter(2, Types.VARCHAR);
        cs.execute();

        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.setDouble(2, maximumPercentageArg);
        cs.registerOutParameter(3, Types.DOUBLE);
        cs.setDouble(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: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 ww w  . j  av  a2  s .  c  om*/
    }
    stmt.close();
}