Applications like MyWi and PDANet are not allowed on the Apple App Store due to getting around user's data network data usage plans (Which networks charge a lot for!)
Check out this app, very simple, lightweight and free!
http://www.junefabrics.com/desktop/
Technical blog discussing various programming languages, frameworks and paradigms. Code snippets and projects are also provided.
Thursday, 26 July 2012
Tuesday, 17 July 2012
JDBC - Calling an Oracle Stored Procedure with CURSOR output
This article explains how to call an Oracle Stored Procedure that returns a Cursor as an output parameter with Java using JDBC.
Things to note:
- JDBC begins it's index's at 1, not 0. I.e. The CallableStatement object's methods such as: getObject must have a parameter with a value of at least 1.
- Once the Connection or CallableStatement objects are closed, the ResultSet will be empty. This is because it only exists as long as the database connection is open. Ensure you take your results before these objects are destroyed.
- oracle.jdbc.OracleCallableStatement and java.sql.CallableStatement offer the same outcome in this example. Therefore, I have opted to use the java.sql library.
- The '?' within the prepareCall parameter is a place holder for a parameter. This is populated (in this example) using the registerOutParameter method, declaring it's expected type.
Oracle Stored Procedure
Java Code
Things to note:
- JDBC begins it's index's at 1, not 0. I.e. The CallableStatement object's methods such as: getObject must have a parameter with a value of at least 1.
- Once the Connection or CallableStatement objects are closed, the ResultSet will be empty. This is because it only exists as long as the database connection is open. Ensure you take your results before these objects are destroyed.
- oracle.jdbc.OracleCallableStatement and java.sql.CallableStatement offer the same outcome in this example. Therefore, I have opted to use the java.sql library.
- The '?' within the prepareCall parameter is a place holder for a parameter. This is populated (in this example) using the registerOutParameter method, declaring it's expected type.
Oracle Stored Procedure
Code Snippet
End of Code Snippet
Java Code
Code Snippet
- // Establishes and returns a new connection to the database
- {
- // Load and register Oracle driver
- // Establish a connection
- }
- // Gets a collection of all accounts within the database
- {
- Collection<Account> accounts = new ArrayList<Account>();
- try
- {
- // Connect
- conn = this.GetConnection();
- // Get ResultSet
- cstmt = conn.prepareCall("{call PACKAGENAME.GET_ACCOUNTS(?)}"); // '?' is a template for our Cursor OUT parameter
- cstmt.registerOutParameter(1, OracleTypes.CURSOR);
- cstmt.execute();
- // Index starts at 1, so we want our first result, which is the Cursor
- // process results one row at a time
- while(rs.next())
- {
- Account acc = new Account(rs.getString(1)); // Account name is the first (and only) result in our Cursor.
- accounts.add(acc); // Add account to our collection of accounts to return
- }
- }
- {
- }
- {
- e.printStackTrace();
- }
- finally
- {
- conn.close();
- cstmt.close();
- }
- return accounts; // Return collection of accounts to caller
- }
- // Account POJO
- public class Account
- {
- {
- this.accountName = accName;
- }
- return this.accountName;
- }
- this.accountName = accountName;
- }
- }
End of Code Snippet
java.lang.IllegalAccessError: oracle/jdbc/driver/OracleCallableStatement
I received this error when attempting to cast the result of a Connection object's prepareCall method.
Solution
Try altering the application to not refer to oracle.jdbc.driver.OracleCallableStatement. It should be oracle.jdbc.OracleCallableStatement.
Reason
For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.
Solution
Try altering the application to not refer to oracle.jdbc.driver.OracleCallableStatement. It should be oracle.jdbc.OracleCallableStatement.
Reason
For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.
Subscribe to:
Posts (Atom)