List of usage examples for java.sql CallableStatement registerOutParameter
default void registerOutParameter(String parameterName, SQLType sqlType) throws SQLException
parameterName
to the JDBC type sqlType . From source file:de.awtools.grooocle.varray.VarrayTest.java
@Test @Ignore/* w w w . j a v a 2 s . 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.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;/*from w w w.ja va 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: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 v a 2 s .com 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:Statement.Statement.java
private void load() { //Display dong Fix va Other Cost try {//from w w w .j a va2 s . c o m PreparedStatement st = cnn .prepareStatement("select Fixed,Other from Expense where ShopID = ? and Date = ?"); st.setString(1, code); st.setString(2, date); ResultSet rs = st.executeQuery(); while (rs.next()) { txtFix.setText(customFormat("VND ###,###,###", rs.getInt(1))); fix = rs.getInt(1); txtOther.setText(customFormat("VND ###,###,###", rs.getInt(2))); other = rs.getInt(2); } } catch (SQLException e) { System.err.println(e.getMessage()); } //Display dong Revenue String query = "{call Revenue_Shop_Date(?,?,?)}"; try { CallableStatement cst = cnn.prepareCall(query); cst.setString(1, code); cst.setString(2, date); cst.registerOutParameter(3, INTEGER); cst.execute(); txtRev.setText(customFormat("VND ###,###,###", cst.getInt(3))); rev = cst.getInt(3); } catch (Exception e) { } //Display dong Profit cost = fix + other; profit = rev - cost; txtProfit.setText(customFormat("VND ###,###,###", profit)); //Display comment try { PreparedStatement st1 = cnn.prepareStatement("select Goal from Shop where ShopID = ?"); st1.setString(1, code); ResultSet rs1 = st1.executeQuery(); while (rs1.next()) { int goal = rs1.getInt(1); if (rev >= goal) { comment.setText("Congrats! The Shop has achieved the goal"); } else { comment.setText("The Shop has failed the goal"); } } } catch (SQLException e) { System.err.println(e.getMessage()); } }
From source file:exifIndexer.MetadataReader.java
public static void walk(String path, boolean is_recursive) { File root = new File(path); File[] list = root.listFiles(); String filePath;//from w w w . jav a 2 s . co m String fileName; String fileExt; String valueName; String tagName; String catName; Metadata metadata; long fileSize; long fileLastModified; java.util.Date utilDate; java.sql.Date sqlDate; String sql = "{ ? = call INSERTIMAGE(?,?,?,?,?) }"; String sqlMetaData = "{ call INSERTMETADATA (?,?,?,?) }"; CallableStatement statement; CallableStatement statementMeta; long result; if (list == null) { return; } for (File f : list) { if (f.isDirectory() && is_recursive) { walk(f.getAbsolutePath(), true); } else { filePath = FilenameUtils.getFullPath(f.getAbsolutePath()); fileName = FilenameUtils.getBaseName(f.getName()); fileExt = FilenameUtils.getExtension(f.getName()); utilDate = new java.util.Date(f.lastModified()); sqlDate = new java.sql.Date(utilDate.getTime()); fileSize = f.length(); try { metadata = ImageMetadataReader.readMetadata(f.getAbsoluteFile()); try { DBHandler db = new DBHandler(); db.openConnection(); Connection con = db.getCon(); // llamada al metodo insertar imagen SQL con (filePath,fileName,fileExtension,fileSize, fileLastModified) statement = con.prepareCall(sql); statement.setString(2, filePath); statement.setString(3, fileName); statement.setString(4, fileExt); statement.setLong(5, fileSize); statement.setDate(6, sqlDate); statement.registerOutParameter(1, java.sql.Types.NUMERIC); statement.execute(); result = statement.getLong(1); // llamada al metodo insertar metadatos SQL con (idImg,valueName, tagName, catName) for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { valueName = tag.getDescription(); tagName = tag.getTagName(); catName = directory.getName(); if (isNull(valueName) || isNull(tagName) || isNull(catName) || valueName.equals("") || tagName.equals("") || catName.equals("") || valueName.length() > 250 || tagName.length() > 250 || catName.length() > 500) { System.out.println("Exif row omitted."); System.out.println("Omitting: [" + catName + "] " + tagName + " " + valueName); } else { statementMeta = con.prepareCall(sqlMetaData); statementMeta.setLong(1, result); statementMeta.setString(2, valueName); statementMeta.setString(3, tagName); statementMeta.setString(4, catName); statementMeta.executeUpdate(); } } } db.closeConnection(); } catch (SQLException ex) { System.err.println("Error with SQL command. \n" + ex); } } catch (ImageProcessingException e) { System.out.println("ImageProcessingException " + e); } catch (IOException e) { System.out.println("IOException " + e); } } } }
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;// w w w . j ava 2s. c o 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; }
From source file:com.cws.esolutions.core.dao.impl.ApplicationDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IApplicationDataDAO#listApplications(int) *//*from www . java 2 s . c o m*/ public synchronized List<String[]> listApplications(final int startRow) throws SQLException { final String methodName = IApplicationDataDAO.CNAME + "#listApplications(final int startRow) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", startRow); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<String[]> responseData = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL listApplications(?, ?)}"); stmt.setInt(1, startRow); stmt.registerOutParameter(2, Types.INTEGER); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("resultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); responseData = new ArrayList<String[]>(); while (resultSet.next()) { String[] data = new String[] { resultSet.getString(1), // APPLICATION_GUID resultSet.getString(2), // APPLICATION_NAME }; if (DEBUG) { DEBUGGER.debug("Value: {}", (Object[]) data); } responseData.add(data); } if (DEBUG) { DEBUGGER.debug("Value: {}", responseData); } } } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return responseData; }
From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * PaymentInfoEFT/*from w ww.j ava2 s. co m*/ * * <p/> * <p/> * <b>DATABASE PROCEDURE:</b> * * @code *FUNCTION fn_get_payinfo_eft * ( * item_no IN VARCHAR2 * ) * RETURN ref_cursor * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>BILLING_PROFILE_ID,</li> * <li>BDOM,</li> * <li>PAYINFO_NAME,</li> * <li>BANK_ACCOUNT_NO,</li> * <li>BANK_NUMBER,</li> * </ul> * * @param itemNo - The item number (e.g. P1-111)of the item we want payment info for * * @return A single Payment Info record * */ @Override public PaymentInfoEFT getPayinfoEFT(String itemNo) throws JSONException { String query = "begin ? := billing_inquiry.fn_get_payinfo_eft( ? ); end;"; Connection conn = null; PaymentInfoEFT c = null; ResultSet rs = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, itemNo); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { c = new PaymentInfoEFT(); c.setBillingProfile(rs.getString("BILLING_PROFILE_ID")); c.setProfileBdom(rs.getInt("BDOM")); c.setCustomerName(rs.getString("PAYINFO_NAME")); c.setBankAccountNumber(rs.getString("BANK_ACCOUNT_NO")); c.setBankNumber(rs.getString("BANK_NUMBER")); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (c == null) { throw JSONException.noDataFound("Null set returned - no data found"); } return c; }
From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * PaymentInfoCheck//from ww w. j a v a2 s. com * <p/> * <p/> * <b>DATABASE PROCEDURE:</b> * * @code *FUNCTION fn_get_payinfo_check * ( * item_no IN VARCHAR2 * ) * RETURN ref_cursor; * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>BILLING_PROFILE_ID,</li> * <li>BDOM,</li> * <li>PAYINFO_NAME,</li> * <li>NET_TERMS,</li> * <li>CHECK_NO,</li> * </ul> * * @param itemNo - The item number (e.g. P1-111)of the item we want payment info for * * @return A single Payment Info record * */ @Override public PaymentInfoCheck getPayinfoCheck(String itemNo) throws JSONException { String query = "begin ? := billing_inquiry.fn_get_payinfo_check( ? ); end;"; // TODO: configure strings ResultSet rs = null; Connection conn = null; PaymentInfoCheck c = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, itemNo); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { c = new PaymentInfoCheck(); c.setBillingProfile(rs.getString("BILLING_PROFILE_ID")); // TODO: configure strings c.setProfileBdom(rs.getInt("BDOM")); c.setCustomerName(rs.getString("PAYINFO_NAME")); c.setNetTerms(rs.getString("NET_TERMS")); c.setCheckNumber(rs.getString("CHECK_NO")); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (c == null) { throw JSONException.noDataFound("Null set returned - no data found"); } return c; }
From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * @section dao_section class BillingDAOImpl * getAllocation// w w w.j a v a 2 s . c o m * * To be used in a caching method where we are pulling all of the allocations at once. The way we can do this * is to merge a date range based set of billing history records with a date range set of allocations. * <p/> * <p/> * <b>DATABASE PROCEDURE:</b> * * @code * FUNCTION fn_get_item_allocations( * item_no IN VARCHAR2 ) * RETURN ref_cursor; * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>ALLOCATION_DATE,</li> * <li>ALLOCATION_T, </li> * <li>ALLOCATION_AMT,</li> * <li>AR_ITEM_NO, </li> * <li>BILL_ITEM_NO, </li> * <li>ITEM_DESCRIPTION, </li> * <li>ITEM_CODE,</li> * <li>AR_ITEM_DATE, </li> * <li>BILL_ITEM_DATE </li> * <li>LICENSE</li> * </ul> * * @param customer : The Customer.accountNo account number of the customer who's allocations we need * @param startDate : The starting date of the allocation - to be merged with a billing history record set * @param endDate : The ending date of the allocation - to be merged with a billing history record set * * @return A list of Allocation objects. * @throws JSONException * * * */ @Override public List<Allocation> getAllocation(String itemNo) throws JSONException { List<Allocation> allocs = new ArrayList<Allocation>(); String query = "begin ? := billing_inquiry.fn_get_item_allocations( ? ); end;"; //TODO: configure ResultSet rs = null; Connection conn = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, itemNo); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { Allocation a = new Allocation(); a.setAllocatedFromItem(rs.getString("AR_ITEM_NO")); a.setAllocatedToItem(rs.getString("BILL_ITEM_NO")); a.setAllocationAmount(rs.getBigDecimal("ALLOCATION_AMT")); a.setAllocationDate(rs.getTimestamp("ALLOCATION_DATE")); a.setItemCode(rs.getString("ITEM_CODE")); a.setItemDescription(rs.getString("ITEM_DESCRIPTION")); a.setLicense(rs.getString("LICENSE")); allocs.add(a); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (allocs == null || allocs.isEmpty()) { throw JSONException.noDataFound("Null set returned - no data found"); } return allocs; }