Example usage for java.sql CallableStatement close

List of usage examples for java.sql CallableStatement close

Introduction

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

Prototype

void close() throws SQLException;

Source Link

Document

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Usage

From source file:de.awtools.grooocle.varray.VarrayTest.java

@Test
@Ignore/*from  w  w  w. ja  va  2s . co  m*/
public void testOraclesVarrayWithPackage() throws Exception {
    CallableStatement cs = null;
    try {
        String arrayElements[] = { "Test3", "Test4", "Test5" };
        //         int n = OracleTypeCOLLECTION.TYPE_PLSQL_INDEX_TABLE;
        //         ArrayDescriptor desc = ArrayDescriptor.createDescriptor();
        ArrayDescriptor desc = ArrayDescriptor.createDescriptor("CP_TEST.t_ROWNUMBER", conn);
        ARRAY newArray = new ARRAY(desc, conn, arrayElements);

        String spCall = "{ call CP_TEST.call_me(?, ?) }";
        cs = conn.prepareCall(spCall);
        cs.setArray(1, newArray);
        cs.registerOutParameter(2, java.sql.Types.INTEGER);

        cs.execute();
        assertEquals(3, cs.getInt(2));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }

}

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

public Object[] getResetPasswordLink(String email, String uuid, String ip) {
    Connection connection = null;
    CallableStatement cstmt = null;
    Object[] obj = null;//w  ww.  j a  v  a2  s  .  c o m
    int rvalue = -1;
    long userId = 0;
    try {
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call wp_forgot_pwd_reset_link(?,?,?,?,?)}");
        cstmt.setString(1, email);
        cstmt.setString(2, uuid);
        cstmt.setString(3, ip);
        cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        cstmt.registerOutParameter(5, java.sql.Types.INTEGER);

        cstmt.execute();

        rvalue = cstmt.getInt(4);
        userId = cstmt.getLong(5);

        obj = new Object[2];
        obj[0] = rvalue;
        obj[1] = userId;
    } 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 obj;
}

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

public int approveQuestion(long userId, long q_id, String is_admin_approved) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;/*from  w  w  w . j a  v a2s . c  om*/
    int approved = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call approve_question(?,?,?,?)}");
        pstmt.setLong(1, userId);
        pstmt.setLong(2, q_id);
        pstmt.setString(3, is_admin_approved);

        pstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        pstmt.execute();
        approved = pstmt.getInt(4);
    } 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 approved;
}

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

public void registerJarFile(String jarPathName) throws SQLException {
    CallableStatement cs2 = null;
    CallableStatement cs2a = null;
    CallableStatement cs3 = null;

    String query2 = "CALL sqlj.install_jar('" + jarPathName + "','" + this.schema + ".JDBCTutorial',0)";
    String query2a = "CALL sqlj.replace_jar('" + jarPathName + "','" + this.schema + ".JDBCTutorial')";
    String query3 = "CALL syscs_util.syscs_set_database_property('derby.database.classpath','" + this.schema
            + ".JDBCTutorial')";

    try {/*from  w  w  w .ja v a 2 s . co  m*/
        System.out.println("Calling " + query2);
        cs2 = con.prepareCall(query2);
        cs2.execute();
    } catch (SQLException e2) {
        JDBCTutorialUtilities.printSQLException(e2);
    } finally {
        if (cs2 != null) {
            cs2.close();
        }
        try {
            System.out.println("Calling " + query2a);
            cs2a = con.prepareCall(query2a);
            cs2a.execute();
        } catch (SQLException e2a) {
            JDBCTutorialUtilities.printSQLException(e2a);
        } finally {
            if (cs2a != null) {
                cs2a.close();
            }
        }
    }
    try {
        System.out.println("Calling " + query3);
        cs3 = con.prepareCall(query3);
        cs3.execute();
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (cs3 != null) {
            cs3.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;/*www.ja  v  a  2s .c o  m*/
    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:datatableinputdata.DataTableInputData.java

private static void WriteToDB(Map<String, String> map /*String num, String name, String filename*/)
        throws SQLException {
    CallableStatement cstmt = null;
    try {//from  ww w  .j  a va2s . c  om
        if (connection == null)
            DBConnect();

        Statement stmt = connection.createStatement();

        ResultSet r = null;

        r = stmt.executeQuery("truncate table DATA");

        for (Map.Entry<String, String> entry : map.entrySet()) {

            r = stmt.executeQuery(
                    "insert into DATA values('" + entry.getValue() + "','" + entry.getKey() + "')");
            /*System.out.println("Country [code= " + entry.getKey() + " , name="
               + entry.getValue() + "]");*/

        }

        /* String day = "";
         cstmt = connection.prepareCall("{call argen666.TESTPRM(?,?)}");
         cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
         cstmt.setString(1, "Monday");
         cstmt.executeUpdate();
         day = cstmt.getString(2);
         System.out.println(day);*/

        /*cstmt = connection.prepareCall("{call ? :=parus.get_license()}");
        cstmt.registerOutParameter(1, java.sql.Types.VARCHAR);
        cstmt.executeUpdate();
        day = cstmt.getString(1);
        System.out.println(day);*/

        //parus.P_INORDERS_SET_STATUS(59945, 109795, 0, TO_DATE('25.09.2014', 'DD.MM.YYYY HH24:MI:SS'), NWARNING, SMSG);
        //java.sql.SQLException: ORA-20103:   ? , ..  "Other"  ?.
        /*cstmt = connection.prepareCall("{call parus.P_INORDERS_SET_STATUS(59945, 109795, 0, TO_DATE('25.09.2014', 'DD.MM.YYYY HH24:MI:SS'), ?, ?)}");
         cstmt.registerOutParameter(1, java.sql.Types.NUMERIC);
         cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
         cstmt.executeUpdate();
         day=cstmt.getString(1);
         System.out.println(day);*/
    } catch (SQLException e) {
        System.out.println(e);
    } finally {
        if (cstmt != null) {
            cstmt.close();
        }
    }
}

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  .  j a  va2 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:common.dao.impl.BaseDAOImpl.java

/**
 * SQL(?)/*from   w w w.  j ava2 s . co  m*/
 * @param queryString
 * @param params
 */
public void executeVoidProcedureSql(final String queryString, final Object[] params) throws Exception {
    Session session = sessionFactory.getCurrentSession();
    session.doWork(new Work() {
        public void execute(Connection conn) throws SQLException {
            ResultSet rs = null;
            CallableStatement call = conn.prepareCall("{" + queryString + "}");
            if (null != params) {
                for (int i = 0; i < params.length; i++) {
                    call.setObject(i + 1, params[i]);
                }
            }
            rs = call.executeQuery();
            call.close();
            rs.close();
        }
    });
}

From source file:com.cws.esolutions.core.dao.impl.ServiceDataDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IServiceDataDAO#removeService(java.lang.String)
 *//*  w  ww . j  a  v  a2  s.com*/
public synchronized boolean removeService(final String datacenter) throws SQLException {
    final String methodName = IServiceDataDAO.CNAME
            + "#removeService(final String datacenter) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", datacenter);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{CALL removeServiceData(?)}");
        stmt.setString(1, datacenter);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        isComplete = (!(stmt.execute()));

        if (DEBUG) {
            DEBUGGER.debug("isComplete: {}", isComplete);
        }
    } catch (SQLException sqx) {
        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return isComplete;
}

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;//from w w w.ja  v  a2  s .  co  m
    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;
}