Example usage for java.sql CallableStatement setString

List of usage examples for java.sql CallableStatement setString

Introduction

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

Prototype

void setString(String parameterName, String x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java String value.

Usage

From source file:es.emergya.bbdd.dao.RoutingHome.java

/**
 * Devuelve la lista de ids de la ruta desde vertice_origen a
 * vertice_destino./*from  ww  w .jav a  2s.co  m*/
 * 
 * Utiliza la funcion shooting_star
 * 
 * @param origin
 * @param goal
 * @return
 */
@Transactional(readOnly = true, rollbackFor = Throwable.class)
private List<Long> shortest_path_shooting_star(final Long origin, final Long goal) {
    final List<Long> lista = new ArrayList<Long>();
    try {
        Session currentSession = getSession();
        CallableStatement consulta = currentSession.connection()
                .prepareCall("{call shortest_path_shooting_star(?,?,?,?,?)}");

        consulta.setString(1,
                "SELECT " + id + "::integer as id, " + source + "::integer as source, " + target
                        + "::integer as target, " + cost + " as cost," + reverse_cost + " as reverse_cost, "
                        + "ST_X(ST_StartPoint(" + the_geom + ")) as x1," + "ST_Y(ST_StartPoint(" + the_geom
                        + ")) as y1," + "ST_X(ST_EndPoint(" + the_geom + ")) as x2," + "ST_Y(ST_EndPoint("
                        + the_geom + ")) as y2," + rule + " as rule, " + to_cost + " as to_cost FROM " + table
        // + " order by " + id
        );
        consulta.setInt(2, origin.intValue());
        consulta.setInt(3, goal.intValue());
        consulta.setBoolean(4, true);
        consulta.setBoolean(5, true);
        log.trace(consulta);
        ResultSet resultado = consulta.executeQuery();

        while (resultado.next())
            lista.add(resultado.getLong("edge_id"));

    } catch (Exception e) {
        log.error("No se pudo calcular la ruta", e);
    }

    return lista;
}

From source file:com.splicemachine.derby.utils.SpliceAdminIT.java

@Test
public void testGetSetLogLevel() throws Exception {
    String logger = "com.splicemachine.derby.iapi.sql.execute.SpliceOperationContext";
    String origLevel = "FRED";
    String newLogLevel = "INFO";
    CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_LOGGER_LEVEL(?)");
    cs.setString(1, logger);
    ResultSet rs = cs.executeQuery();
    while (rs.next()) {
        origLevel = rs.getString(1);/*  w w  w .  jav  a  2 s .c  om*/
    }

    try {
        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_SET_LOGGER_LEVEL(?,?)");
        cs.setString(1, logger);
        cs.setString(2, newLogLevel);
        cs.execute();

        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_LOGGER_LEVEL(?)");
        cs.setString(1, logger);
        rs = cs.executeQuery();
        String currentLogLevel = "FRED";
        while (rs.next()) {
            currentLogLevel = rs.getString(1);
        }
        Assert.assertNotEquals("FRED", currentLogLevel);
        Assert.assertEquals(newLogLevel, currentLogLevel);
    } finally {
        // reset to orig value
        cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_SET_LOGGER_LEVEL(?,?)");
        cs.setString(1, logger);
        cs.setString(2, origLevel);
        cs.execute();
    }

    DbUtils.closeQuietly(rs);

}

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;/*from  www .j  a  v  a  2  s  .co  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:eionet.cr.util.virtuoso.VirtuosoJdbcDriverTest.java

/**
 * Test if CR uses correct Virtuoso JDBC driver. It shouldn't get "Too many open statements" error.
 *
 * @throws SQLException When problem with connecting to Virtuoso.
 *///w  w  w .j  a  v  a  2  s  .  c o  m
@Test
public void testTooManyOpenStmts() throws SQLException {

    VirtuosoConnectionPoolDataSource dbsource = new VirtuosoConnectionPoolDataSource();

    String testDbURI = GeneralConfig.getRequiredProperty(GeneralConfig.VIRTUOSO_DB_URL);
    URI uri = URI.create(testDbURI.substring(5));

    dbsource.setServerName(uri.getHost());
    dbsource.setPortNumber(uri.getPort());
    dbsource.setPassword(GeneralConfig.getRequiredProperty(GeneralConfig.VIRTUOSO_DB_PWD));
    dbsource.setUser(GeneralConfig.getRequiredProperty(GeneralConfig.VIRTUOSO_DB_USR));
    dbsource.setCharset("UTF-8");
    VirtuosoPooledConnection pooledConnection = (VirtuosoPooledConnection) dbsource.getPooledConnection();
    virtuoso.jdbc4.VirtuosoConnection con = pooledConnection.getVirtuosoConnection();
    String jdbcComp = "DB.DBA.TTLP (?, ?, ?, ?)";
    CallableStatement stmt = null;
    int MAXIT = 10000;
    for (int i = 0; i < MAXIT; i++) {
        try {
            stmt = con.prepareCall(jdbcComp);
            stmt.setString(1, "");
            stmt.setString(2, "");
            stmt.setString(3, DUMMY_GRAPH_URI);
            stmt.setInt(4, 256);
            stmt.execute();
            con.commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail("can't add data to virtuoso. ");
        } finally {
            if (stmt != null) {
                stmt.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;// ww w  . j ava 2 s .c  om
    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;
}

From source file:com.mobilewallet.admin.dao.QuestionDAO.java

public int submitQuestion(String question, String qType, String option1, String option2, String option3,
        String option4, String answer, String explanation, String isAdminApproved) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;/* www. j a v  a2  s  .c om*/
    int submitted = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call SUBMIT_QUESTION(?,?,?,?,?,?,?,?,?,?)}");
        pstmt.setString(1, qType);
        pstmt.setString(2, question);
        pstmt.setString(3, option1);
        pstmt.setString(4, option2);
        pstmt.setString(5, option3);
        pstmt.setString(6, option4);
        pstmt.setString(7, answer);
        pstmt.setString(8, explanation);
        pstmt.setString(9, isAdminApproved);
        pstmt.registerOutParameter(10, java.sql.Types.INTEGER);
        pstmt.execute();
        submitted = pstmt.getInt(10);
    } 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;
}

From source file:com.mobilewallet.credits.dao.CreditsDAO.java

public int updateCredits(long userId, String isCorrect, int position) {
    int updated = 0;
    Connection connection = null;
    CallableStatement cstmt = null;
    try {//w  ww .jav  a 2  s  .  c o  m
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call update_credits_proc(?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, isCorrect);
        cstmt.setInt(3, position);
        cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        cstmt.execute();

        updated = cstmt.getInt(4);
    } 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 updated;
}

From source file:com.mobilewallet.users.dao.UserDAO.java

public int updateProfile(long userId, String mCode, String mobileNumber, String dob, String gender,
        String occupation, String income) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;//from  w w w .  jav  a2 s  .  c  o m
    int updated = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call UPDATE_PROFILE(?,?,?,?,?,?,?,?)}");
        pstmt.setLong(1, userId);
        pstmt.setString(2, mCode);
        pstmt.setString(3, mobileNumber);
        pstmt.setString(4, dob);
        pstmt.setString(5, gender);
        pstmt.setString(6, occupation);
        pstmt.setString(7, income);
        pstmt.registerOutParameter(8, java.sql.Types.INTEGER);
        pstmt.execute();
        updated = 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 updated;
}

From source file:de.anycook.db.mysql.DBGetRecipe.java

public String getImageName(String recipe) throws SQLException {
    CallableStatement call = connection.prepareCall("{call recipe_image(?)}");
    call.setString(1, recipe);
    ResultSet data = call.executeQuery();
    if (data.next()) {
        String imageName = data.getString("imagename");
        String categoryImage = "category/" + data.getString("image");

        return imageName == null || imageName.equals("") ? categoryImage : imageName;

    }/*w w w . java  2  s .  c o  m*/

    return "nopicture.png";

}

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  www  .j  ava2s  .c  o m

        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();
        }
    }
}