Example usage for java.sql CallableStatement execute

List of usage examples for java.sql CallableStatement execute

Introduction

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

Prototype

boolean execute() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

Usage

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./*w w w  .  java  2  s.  c  o  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;
}

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

/**
 * /*w w w.  jav a2s . co m*/
 * @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 www.j a v  a2s .  c om
 * @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  www. ja  v  a  2 s  . c om*/
 * @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);
        }
    }
}

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

/**
 * ???//from  w w  w  . j ava  2s.c o  m
 * @param declNo
 * @return
 */
public static String getDeclProductFromEnt(String declNo) {
    String declProductFromEnt = null;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_GetDeclProductFromEnt(?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.execute();
        rs = proc.getResultSet();
        while (rs.next()) {
            declProductFromEnt = rs.getString("RESULT_CONTENT");
            break;
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N51", e);
    } catch (Exception e) {
        log.error("N52", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N53", e);
        }
    }
    return declProductFromEnt;
}

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

/**
 * ???CIQ???????CIQ?/*from  w w  w.j a v a2s.co m*/
 */
public static int saveDeclInfo(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    String call = "{call Pro_SaveDeclInfo(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N48", e);
    } catch (Exception e) {
        log.error("N49", e);
    } finally {
        try {
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N50", e);
        }
    }
    return retCode;
}

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

/**
 * ??//from  w w w .  ja v  a 2  s .  c  o m
 */
public static int declFlagAction(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    String call = "{call Pro_DeclFlagAction(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N33", e);
    } catch (Exception e) {
        log.error("N34", e);
    } finally {
        try {
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N35", e);
        }
    }
    return retCode;
}

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

/**
 * ?:?/*  w  w w  .  j a  v a2 s.  c  om*/
 * @return
 */
public static int checkRapidRelease(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckRapidRelease(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N60", e);
    } catch (Exception e) {
        log.error("N61", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N62", e);
        }
    }
    return retCode;
}

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

/**
 * ?????// w  w  w . j a  va  2 s .  co  m
 * @param declNo
 * @return
 */
public static int checkDeclProductPerfect(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckDeclProductPerfect(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error(e);
    } catch (Exception e) {
        log.error(e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error(e);
        }
    }
    return retCode;
}

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

public static int checkDeclProductSampling(String declNo) {
    int retCode = -1;
    Connection conn = null;/*  ww  w  .ja v a2  s .c  o  m*/
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckDeclProductSampling(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N57", e);
    } catch (Exception e) {
        log.error("N58", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N59", e);
        }
    }
    return retCode;
}