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:cn.cuizuoli.appranking.typehandler.CountryTypeHandler.java

@Override
public Country getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    Country country = null;/*w ww.  jav  a 2s. c  om*/
    String s = cs.getString(columnIndex);
    if (StringUtils.isNotEmpty(s)) {
        country = Country.getObject(s);
    }
    return country;
}

From source file:cn.cuizuoli.appranking.typehandler.FeedTypeTypeHandler.java

@Override
public FeedType getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    FeedType feedType = null;/*from w ww  . j a v a  2  s.c  o  m*/
    String s = cs.getString(columnIndex);
    if (StringUtils.isNotEmpty(s)) {
        feedType = FeedType.getObject(s);
    }
    return feedType;
}

From source file:cn.cuizuoli.appranking.typehandler.MediaTypeTypeHandler.java

@Override
public MediaType getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    MediaType mediaType = null;//from ww w. j  ava2s .  com
    String s = cs.getString(columnIndex);
    if (StringUtils.isNotEmpty(s)) {
        mediaType = MediaType.getObject(s);
    }
    return mediaType;
}

From source file:org.ownchan.server.persistence.typehandler.auto.PersistableJsonDataTypeHandler.java

@Override
public PersistableJsonData getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    return createDbJsonDataFromString(cs.getString(columnIndex));
}

From source file:cn.cuizuoli.appranking.typehandler.DeviceTypeTypeHandler.java

@Override
public DeviceType getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    DeviceType deviceType = null;/*  w  w w. ja  v a 2 s .  c o m*/
    String s = cs.getString(columnIndex);
    if (StringUtils.isNotEmpty(s)) {
        deviceType = DeviceType.getObject(s);
    }
    return deviceType;
}

From source file:edu.harvard.i2b2.crc.loader.dao.CRCLoaderDAO.java

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

    if (serverType.equalsIgnoreCase(DataSourceLookupDAOFactory.SQLSERVER)) {
        String errorMsg = callStmt.getString(outParamIndex);
        if (errorMsg != null) {
            System.out.println("error codde" + errorMsg);
            throw new I2B2Exception("Error from stored procedure [" + errorMsg + "]");
        }//from w  ww. j ava2  s .com
    }
}

From source file:org.unitime.timetable.util.BlobRoomAvailabilityService.java

protected Document receiveResponse() throws IOException, DocumentException {
    try {//from w w  w.  j a  v a  2  s  . com
        SessionImplementor session = (SessionImplementor) new _RootDAO().getSession();
        Connection connection = session.getJdbcConnectionAccess().obtainConnection();
        String response = null;
        try {
            CallableStatement call = connection.prepareCall(iResponseSql);
            call.registerOutParameter(1, java.sql.Types.CLOB);
            call.execute();
            response = call.getString(1);
            call.close();
        } finally {
            session.getJdbcConnectionAccess().releaseConnection(connection);
        }
        if (response == null || response.length() == 0)
            return null;
        StringReader reader = new StringReader(response);
        Document document = (new SAXReader()).read(reader);
        reader.close();
        return document;
    } catch (Exception e) {
        sLog.error("Unable to receive response: " + e.getMessage(), e);
        return null;
    } finally {
        _RootDAO.closeCurrentThreadSessions();
    }
}

From source file:org.squale.welcom.struts.bean.JCryptable.java

/**
 * Crypte les attributs crypts d'un Bean Date de cration : (07/10/2002 15:57:23)
 * /*from  w  w w . j a  va 2 s  .  c om*/
 * @param conn la connection
 * @throws JCryptableException exception pouvant etre levee
 */
public void crypte(final java.sql.Connection conn) throws JCryptableException {
    try {
        final int nbAttr = cryptableAttr.length;

        // Pour chaque attr  crypter, appelle la procdure stocke de cryptage auprs de la BDD
        for (int i = 0; i < nbAttr; i++) {
            final String attr = cryptableAttr[i];

            final String value = (String) PropertyUtils.getProperty(this, attr);

            if ((value != null) && (value.length() > 0)) {
                final CallableStatement cs = conn.prepareCall("{? = call crypte_FCT(?)}");
                cs.registerOutParameter(1, java.sql.Types.VARCHAR);
                cs.setString(2, value);

                cs.executeUpdate();
                PropertyUtils.setProperty(this, attr, cs.getString(1));
                cs.close();
            }
        }
    } catch (final SQLException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final IllegalAccessException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final InvocationTargetException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final NoSuchMethodException ex) {
        throw new JCryptableException(ex.getMessage());
    }
}

From source file:org.squale.welcom.struts.bean.JCryptable.java

/**
 * Decrypte les attributs crypts d'un Bean Date de cration : (07/10/2002 15:57:13)
 * /*from   w w w  .  ja  v a2s  . co  m*/
 * @param conn la connection
 * @throws JCryptableException exception pouvant etre levee
 */
public void decrypte(final java.sql.Connection conn) throws JCryptableException {
    try {
        if (cryptableAttr != null) {
            final int nbAttr = cryptableAttr.length;

            // Pour chaque attr crypt, appelle la procdure stocke de dcryptage auprs de la BDD
            for (int i = 0; i < nbAttr; i++) {
                final String attr = cryptableAttr[i];

                final String value = (String) PropertyUtils.getProperty(this, attr);

                if ((value != null) && (value.length() > 0)) {
                    final CallableStatement cs = conn.prepareCall("{? = call decrypte_FCT(?)}");
                    cs.registerOutParameter(1, java.sql.Types.VARCHAR);
                    cs.setString(2, value);

                    cs.executeUpdate();
                    PropertyUtils.setProperty(this, attr, cs.getString(1));
                    cs.close();
                }
            }
        }
    } catch (final SQLException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final IllegalAccessException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final InvocationTargetException ex) {
        throw new JCryptableException(ex.getMessage());
    } catch (final NoSuchMethodException ex) {
        throw new JCryptableException(ex.getMessage());
    }
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given stored procedure or function in the RDBMS using the given List 
 * of {@link jongo.jdbc.StoredProcedureParam}.
 * @param database database name or schema where to execute the stored procedure or function
 * @param queryName the name of the stored procedure or function. This gets converted to a {call foo()} statement.
 * @param params a List of {@link jongo.jdbc.StoredProcedureParam} used by the stored procedure or function.
 * @return a List of {@link jongo.rest.xstream.Row} with the results of the stored procedure (if out parameters are given)
 * or the results of the function.//ww  w  . ja va2  s  . co  m
 * @throws SQLException
 */
public static List<Row> executeQuery(final String database, final String queryName,
        final List<StoredProcedureParam> params) throws SQLException {
    l.debug("Executing stored procedure " + database + "." + queryName);

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(database);
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    final String call = JongoUtils.getCallableStatementCallString(queryName, params.size());
    List<Row> rows = new ArrayList<Row>();

    Connection conn = null;
    CallableStatement cs = null;
    try {
        l.debug("Obtain connection from datasource");
        conn = run.getDataSource().getConnection();

        l.debug("Create callable statement for " + call);
        cs = conn.prepareCall(call);

        l.debug("Add parameters to callable statement");
        final List<StoredProcedureParam> outParams = addParameters(cs, params);

        l.debug("Execute callable statement");
        if (cs.execute()) {
            l.debug("Got a result set " + queryName);
            ResultSet rs = cs.getResultSet();
            JongoResultSetHandler handler = new JongoResultSetHandler(true);
            rows = handler.handle(rs);
        } else if (!outParams.isEmpty()) {
            l.debug("No result set, but we are expecting OUT values from " + queryName);
            Map<String, String> results = new HashMap<String, String>();
            for (StoredProcedureParam p : outParams) {
                results.put(p.getName(), cs.getString(p.getIndex())); // thank $deity we only return strings
            }
            rows.add(new Row(0, results));
        }
    } catch (SQLException ex) {
        l.debug(ex.getMessage());
        throw ex;
    } finally {
        try {
            if (cs != null && !cs.isClosed())
                cs.close();
        } catch (SQLException ex) {
            l.debug(ex.getMessage());
        }
        try {
            if (conn != null && !conn.isClosed())
                conn.close();
        } catch (SQLException ex) {
            l.debug(ex.getMessage());
        }
    }
    l.debug("Received " + rows.size() + " results.");
    return rows;
}