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:org.kawanfw.test.run.callable.CallableStatementTest.java

public static void callableStatementTest(Connection connection) throws Exception {
    String testString = "to be capitalized";

    CallableStatement upperProc = connection.prepareCall("{ ? = call upper( ? ) }");
    upperProc.registerOutParameter(1, Types.VARCHAR);
    upperProc.setString(2, testString);/*from   ww  w. j  av  a2 s.  c o m*/
    boolean isResultSet = upperProc.execute();

    System.out.println("isResultSet: " + isResultSet);
    String upperCased = upperProc.getString(1);

    String stringparm = upperProc.getString(2);
    System.out.println("stringparm: " + stringparm);

    upperProc.close();

    Assert.assertEquals(testString.toUpperCase(), upperCased);

    System.out.println("test string: " + testString);
    System.out.println("result: " + upperCased);
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java

private static String executeCall(Connection conn, String sql, int retPid, Object... params) {

    CallableStatement stmt = null;
    String ret = null;//from ww w.ja v  a 2  s  .c  o  m

    try {
        conn.setAutoCommit(false);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        return ret;
    }

    try {

        stmt = conn.prepareCall(sql);
        int i = 1;
        for (Object o : params) {
            stmt.setObject(i, o);
            i++;
        }

        stmt.registerOutParameter(retPid, Types.VARCHAR);

        stmt.execute();
        ret = stmt.getString(retPid);

        conn.commit();

    } catch (SQLException e) {
        //         log.error(e);
        //         e.printStackTrace();
        //         System.out.println(e.getLocalizedMessage());
        ret = null;

        try {
            conn.rollback();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            log.error(e1);
            e1.printStackTrace();
            System.out.println(e1.getLocalizedMessage());
            ret = null;
        }

    } finally {
        closeSQLObjects(stmt, null);
    }

    try {
        conn.setAutoCommit(true);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        ret = null;
    }

    return ret;
}

From source file:Main.java

public static int storedProcWithResultSet() throws Exception {
    Connection conn = null;/*from  w ww . j ava  2  s .  c o m*/
    CallableStatement cs = conn.prepareCall("{? = call proc (?,?,?,?,?,?,?)}");

    // register input parameters
    cs.setString(2, "");
    cs.setString(3, "");
    cs.setString(4, "123");
    // regsiter ouput parameters
    cs.registerOutParameter(5, java.sql.Types.CHAR);
    cs.registerOutParameter(6, java.sql.Types.CHAR);
    cs.registerOutParameter(7, java.sql.Types.CHAR);

    // Procedure execution
    ResultSet rs = cs.executeQuery();

    ResultSetMetaData rsmd = rs.getMetaData();
    int nbCol = rsmd.getColumnCount();
    while (rs.next()) {
        for (int i = 1; i <= nbCol; i++) {
            System.out.println(rs.getString(i));
            System.out.println(rs.getString(i));
        }
    }
    // OUTPUT parameters
    System.out.println("return code of Stored procedure = : " + cs.getInt(1));
    for (int i = 5; i <= 7; i++)
        System.out.println("parameter " + i + " : " + cs.getString(i));
    return cs.getInt(1);
}

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

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

From source file:com.fusesource.examples.horo.db.typehandler.StarSignTypeHandler.java

@Override
public StarSign getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
    String name = callableStatement.getString(i);
    return (name == null) ? null : StarSign.getInstance(name);
}

From source file:org.gbif.drupal.mybatis.EnumDictTypeHandler.java

@Override
public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
    return lookup(cs.getString(columnIndex));
}

From source file:com.tomoare.mybatis.type.EnumValueTypeHandler.java

@Override
public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    String s = cs.getString(columnIndex);
    return getEnum(s);
}

From source file:com.ace.commons.mybatis.type.StringToSetTypeHander.java

@Override
public Set<Long> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    String result = cs.getString(columnIndex);
    return stringToSet(result, null);
}

From source file:com.huifu.mybatis.handler.LikeTypeHandler.java

@Override
public String getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
    return arg0.getString(arg1);
}

From source file:com.github.javaplugs.mybatis.TreeNodeTypeHandler.java

@Override
public TreeNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    String jsonSource = cs.getString(columnIndex);
    if (jsonSource != null) {
        return fromString(jsonSource);
    }//from w w  w .  j  a va2s .c om
    return null;
}