List of usage examples for java.sql CallableStatement getInt
int getInt(String parameterName) throws SQLException;
INTEGER
parameter as an int
in the Java programming language. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); String simpleProc = "{ call simpleproc(?) }"; CallableStatement cs = conn.prepareCall(simpleProc); cs.registerOutParameter(1, java.sql.Types.INTEGER); cs.execute();//from w w w . j a va 2 s.c om int param1 = cs.getInt(1); System.out.println("param1=" + param1); ParameterMetaData pmeta = cs.getParameterMetaData(); if (pmeta == null) { System.out.println("Vendor does not support ParameterMetaData"); } else { System.out.println(pmeta.getParameterType(1)); } conn.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection conn = null;//from ww w. ja va2 s . co m String query = "begin proc(?,?,?); end;"; CallableStatement cs = conn.prepareCall(query); cs.setString(1, "string parameter"); cs.setInt(2, 1); cs.registerOutParameter(2, Types.INTEGER); cs.registerOutParameter(3, Types.INTEGER); cs.execute(); int parm2 = cs.getInt(2); // get the result from OUTPUT #2 int parm3 = cs.getInt(3); // get the result from OUTPUT #3 }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); // Step-2: identify the stored procedure String simpleProc = "{ call simpleproc(?) }"; // Step-3: prepare the callable statement CallableStatement cs = conn.prepareCall(simpleProc); // Step-4: register output parameters ... cs.registerOutParameter(1, java.sql.Types.INTEGER); // Step-5: execute the stored procedures: proc3 cs.execute();// w w w .ja v a 2s .c o m // Step-6: extract the output parameters int param1 = cs.getInt(1); System.out.println("param1=" + param1); // Step-7: get ParameterMetaData ParameterMetaData pmeta = cs.getParameterMetaData(); if (pmeta == null) { System.out.println("Vendor does not support ParameterMetaData"); } else { System.out.println(pmeta.getParameterType(1)); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getOracleConnection(); // Step-2: identify the stored procedure String proc3StoredProcedure = "{ call proc3(?, ?, ?) }"; // Step-3: prepare the callable statement CallableStatement cs = conn.prepareCall(proc3StoredProcedure); // Step-4: set input parameters ... // first input argument cs.setString(1, "abcd"); // third input argument cs.setInt(3, 10);/*from ww w. j a v a 2 s. c o m*/ // Step-5: register output parameters ... cs.registerOutParameter(2, java.sql.Types.VARCHAR); cs.registerOutParameter(3, java.sql.Types.INTEGER); // Step-6: execute the stored procedures: proc3 cs.execute(); // Step-7: extract the output parameters // get parameter 2 as output String param2 = cs.getString(2); // get parameter 3 as output int param3 = cs.getInt(3); System.out.println("param2=" + param2); System.out.println("param3=" + param3); conn.close(); }
From source file:Main.java
public static int storedProcWithResultSet() throws Exception { Connection conn = null;// w ww . java2 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:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ???CIQ???????CIQ?// w w w.j a va 2s . c o 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 ww. ja va 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
/** * ?:?//ww w .j a v a2 s .c o m * @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
/** * ?????//from w w w .ja va 2s. c om * @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;/*from ww w .j av 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; }