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:Main.java

public static void main(String[] args) throws Exception {
    // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system",
            "manager");
    String plsql = " declare " + "    p_id varchar2(20) := null; " + "    l_rc sys_refcursor;" + " begin "
            + "    p_id := ?; " + "    ? := 'input parameter was = ' || p_id;" + "    open l_rc for "
            + "        select 1 id, 'abc' name from dual; " + "    ? := l_rc;" + " end;";

    CallableStatement cs = c.prepareCall(plsql);
    cs.setString(1, "12345");
    cs.registerOutParameter(2, Types.VARCHAR);
    //  cs.registerOutParameter(3, OracleTypes.CURSOR);

    cs.execute();/* w w  w . j a  v a 2s  .c o m*/

    System.out.println("Result = " + cs.getObject(2));

    ResultSet cursorResultSet = (ResultSet) cs.getObject(3);
    while (cursorResultSet.next()) {
        System.out.println(cursorResultSet.getInt(1) + " " + cursorResultSet.getString(2));
    }
    cs.close();
    c.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName(DB_DRIVER);//from   w  ww.  j  av  a2  s.  c  o  m
    Connection dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);

    CallableStatement callableStatement = null;
    String insertStoreProc = "{call insertPERSON(?,?,?,?)}";

    java.util.Date today = new java.util.Date();
    callableStatement = dbConnection.prepareCall(insertStoreProc);
    callableStatement.setInt(1, 1000);
    callableStatement.setString(2, "name");
    callableStatement.setString(3, "system");
    callableStatement.setDate(4, new java.sql.Date(today.getTime()));

    callableStatement.executeUpdate();
    System.out.println("Record is inserted into PERSON table!");
    callableStatement.close();
    dbConnection.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String URL = "jdbc:microsoft:sqlserver://yourServer:1433;databasename=pubs";
    String userName = "yourUser";
    String password = "yourPassword";

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    Connection con = DriverManager.getConnection(URL, userName, password);
    CallableStatement callstmt = con
            .prepareCall("INSERT INTO myIdentTable (col2) VALUES (?);SELECT @@IDENTITY");
    callstmt.setString(1, "testInputBatch");
    callstmt.execute();/*from   w  w  w.j a  v  a  2s. c o m*/

    int iUpdCount = callstmt.getUpdateCount();
    boolean bMoreResults = true;
    ResultSet rs = null;
    int myIdentVal = -1; // to store the @@IDENTITY

    while (bMoreResults || iUpdCount != -1) {
        rs = callstmt.getResultSet();
        if (rs != null) {
            rs.next();
            myIdentVal = rs.getInt(1);
        }
        bMoreResults = callstmt.getMoreResults();
        iUpdCount = callstmt.getUpdateCount();
    }
    callstmt.close();
    con.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName(DB_DRIVER);/*from   w w  w.  j  a v a2s . c  o m*/
    Connection dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);

    CallableStatement callableStatement = null;
    String getPERSONByUserIdSql = "{call getPERSONByUserId(?,?,?,?)}";
    callableStatement = dbConnection.prepareCall(getPERSONByUserIdSql);

    callableStatement.setInt(1, 10);
    callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
    callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
    callableStatement.registerOutParameter(4, java.sql.Types.DATE);

    callableStatement.executeUpdate();

    String userName = callableStatement.getString(2);
    String createdBy = callableStatement.getString(3);
    Date createdDate = callableStatement.getDate(4);

    System.out.println("UserName : " + userName);
    System.out.println("CreatedBy : " + createdBy);
    System.out.println("CreatedDate : " + createdDate);
    callableStatement.close();
    dbConnection.close();
}

From source file:com.skilrock.lms.common.db.DBConnect.java

public static void closeCstmt(CallableStatement cstmt) {
    try {// ww  w  . ja  v a 2  s. co  m
        if (cstmt == null)
            logger.info("Callable Statement Already Closed Or Empty");
        else
            cstmt.close();
    } catch (SQLException ex) {
        logger.error("Problem While closing Callable Statement");
        ex.printStackTrace();
    }
}

From source file:ips1ap101.lib.core.db.util.DB.java

public static boolean close(CallableStatement callableStatement) {
    if (callableStatement != null) {
        try {/*  w  ww . j  a va 2 s .c o m*/
            callableStatement.close();
            return true;
        } catch (SQLException ex) {
            Bitacora.logFatal(ex);
        }
    }
    return false;
}

From source file:com.alibaba.druid.pool.DBCPTest.java

public void test_dbcp() throws Exception {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(MockDriver.class.getName());
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setMaxOpenPreparedStatements(100);
    dataSource.setPoolPreparedStatements(true);

    final String sql = "selelct 1";
    {//from   w w  w  . ja  va  2  s . co m
        Connection conn = dataSource.getConnection();
        CallableStatement stmt = conn.prepareCall(sql);
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        CallableStatement stmt = conn.prepareCall(sql);
        stmt.close();
        conn.close();
    }
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * /* w w w.  j  a  v a  2  s.  c  om*/
 * @param declNo
 */
public static void rapidRelease(String declNo) {
    Connection conn = null;
    CallableStatement proc = null;
    String call = "{call Pro_RapidRelease(?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.execute();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N63", e);
    } catch (Exception e) {
        log.error("N64", e);
    } finally {
        try {
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N65", e);
        }
    }
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * ?????//from  ww  w  . j  ava2 s.  co  m
 * @param declNo
 */
public static void calculateAllDeclProductSampling(String declNo) {
    Connection conn = null;
    CallableStatement proc = null;
    String call = "{call Pro_CalculateAllDeclProductSampling(?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.execute();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N36", e);
    } catch (Exception e) {
        log.error("N37", e);
    } finally {
        try {
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N38", e);
        }
    }
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * ????/*from w w w.j  av a 2  s .  co  m*/
 * @param declNo
 */
public static void saveDeclInfoAbnormal(String declNo, int flg) {
    Connection conn = null;
    CallableStatement proc = null;
    String call = "{call Pro_SaveDeclInfoAbnormal(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.setInt(2, flg);
        proc.execute();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N42", e);
    } catch (Exception e) {
        log.error("N43", e);
    } finally {
        try {
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N44", e);
        }
    }
}