Registering a bool out parameter in callable statement

Hi all..
Can we register a bool type as a out parameter.in oraclecallablestatement.....
Class definition says only char varchar long raw longraw can be registered as out parameters..
if we cant.. what how can we capture a bool o/p from a function....please help

user21786,
We discussed this issue just a few days ago. Boolean is not a supported native type in oraclecallablestatement. Check the thread for workarounds.
--Shiv                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Registering boolean Out parameter

    Hi all,
    Im trying to register a boolean out parameter in a callable statement. I went through a thread which said boolean types are not supported by JDBC. Is it the same case with my scenario?
    Thanks.

    If your attribute is defined as Boolean, you should be able to use oracle callablablestatement as follows... oraclecallablestatement.setBoolean(12,getAttribute());
    Here's some sample code from my EO. Is your syntax similar?
    public class AcctMapEOImpl extends  OAPlsqlEntityImpl
    public void insertRow()
    try
    OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getDBTransaction();
    String s = "begin spl_jdev_api_account_map.spl_create_acct(p_cont_cd=>:1,p_consolidate_cd=>:2,     p_customer=>:3,p_req_asn=>:4,     p_sonic_label=>:5,p_req_conversion_date=>:6,p_override_asn=>:7,p_vendor_name=>:8,p_building =>:9,p_revision =>:10,     p_acct_lookup_use_whse_flag =>:11,p_asn_under_rcpt_tolerance=>:12,p_asn_over_rcpt_tolerance=>:13,p_created_by=>:14,p_creation_date=>:15,p_last_updated_by=>:16,p_last_update_date=>:17,p_cancel_asn_yn=>:18,";
    String t = "p_use_flex_valueset=>:19,p_po_asn_yn=>:20,p_prepaid_ups_flag=>:21,p_eia_label=>:22,p_exe_flag=>:23,p_header_label_template=>:24,p_line_label_template=>:25,p_all_lpns=>:26,p_internal_asn=>:27,p_print_pickslip =>:28,p_replace_asn_flag =>:29,p_get_line_ref_flag=>:30,p_commercial_inv_flag=>:31,p_req_asn_search =>:32,p_asn_ship_days =>:33,p_asn_receipt_days=>:34,p_asn_creation_days =>:35,p_asn_conversion_flag =>:36,p_min_shelf_life_days=>:37,p_restrict_expired_pick =>:38,";
    String u = "p_ars_rules=>:39,p_restock_ord_tgt_oms=>:40,p_attribute_category =>:41,p_attribute1 =>:42,p_attribute2 =>:43,p_attribute3 =>:44,p_attribute4 =>:45,p_attribute5=>:46,p_attribute6=>:47,p_attribute7 =>:48,p_attribute8=>:49,p_attribute9=>:50,p_attribute10=>:51,p_attribute11 =>:52,p_attribute12 =>:53,p_attribute13 =>:54,p_attribute14 =>:55,p_attribute15 =>:56,p_header_label_template1 => :57,p_header_label_template2 =>:58,p_header_label_template3 => :59,";
    String v = "p_header_label_template4 => :60,p_header_label_template5 =>:61,p_header_label_template6 => :62,p_header_label_template7 => :63,p_header_label_template8 =>:64,p_header_label_template9 => :65,p_header_label_template10 => :66,p_header_label_template11 =>:67,p_header_label_template12 => :68,p_header_label_template13 => :69,p_header_label_template14 =>:70,p_header_label_template15 => :71,p_line_label_template1 => :72,p_line_label_template2 => :73," ;
    String w = "p_line_label_template3 => :74,p_line_label_template4 => :75,p_line_label_template5 => :76,p_line_label_template6 => :77,p_line_label_template7 => :78,p_line_label_template8 => :79,p_line_label_template9 => :80,p_line_label_template10 => :81,p_line_label_template11 => :82,p_line_label_template12 => :83,p_line_label_template13 => :84,p_line_label_template14 => :85,p_line_label_template15 => :86); end;";
    String x = (s+t+u+v+w);
    OracleCallableStatement oraclecallablestatement = (OracleCallableStatement)oadbtransactionimpl.createCallableStatement(x, -1);
    oraclecallablestatement.setString(1,getContCd());
    oraclecallablestatement.setString(2,getConsolidateCd());
    oraclecallablestatement.setString(3,getCustomer());
    oraclecallablestatement.setString(4,getReqAsn());
    oraclecallablestatement.setString(5,getSonicLabel());
    oraclecallablestatement.setDATE(6,getReqConversionDate());
    oraclecallablestatement.setString(7,getOverrideAsn());
    oraclecallablestatement.setString(8,getVendorName());
    oraclecallablestatement.setString(9,getBuilding());
    oraclecallablestatement.setString(10,getRevision());
    oraclecallablestatement.setString(11,getAcctLookupUseWhseFlag());
    oraclecallablestatement.setNUMBER(12,getAsnUnderRcptTolerance());
    oraclecallablestatement.setNUMBER(13,getAsnOverRcptTolerance());
    oraclecallablestatement.setNUMBER(14,getCreatedBy());
    oraclecallablestatement.setDATE(15,getCreationDate());
    oraclecallablestatement.setNUMBER(16,getLastUpdatedBy());
    oraclecallablestatement.setDATE(17,getLastUpdateDate());
    oraclecallablestatement.setString(18,getCancelAsnYn());
    oraclecallablestatement.setString(19,getUseFlexValueset());
    oraclecallablestatement.setString(20,getPoAsnYn());
    oraclecallablestatement.setString(21,getPrepaidUpsFlag());
    oraclecallablestatement.setString(22,getEiaLabel());
    oraclecallablestatement.setString(23,getExeFlag());
    oraclecallablestatement.setString(24,getHeaderLabelTemplate());
    oraclecallablestatement.setString(25,getLineLabelTemplate());
    oraclecallablestatement.setString(26,getAllLpns());
    oraclecallablestatement.setString(27,getInternalAsn());
    oraclecallablestatement.setString(28,getPrintPickslip());
    oraclecallablestatement.setString(29,getReplaceAsnFlag());
    oraclecallablestatement.setString(30,getGetLineRefFlag());
    oraclecallablestatement.setString(31,getCommercialInvFlag());
    oraclecallablestatement.setString(32,getReqAsnSearch());
    oraclecallablestatement.setNUMBER(33,getAsnShipDays());
    oraclecallablestatement.setNUMBER(34,getAsnReceiptDays());
    oraclecallablestatement.setNUMBER(35,getAsnCreationDays());
    oraclecallablestatement.setString(36,getAsnConversionFlag());
    oraclecallablestatement.setNUMBER(37,getMinShelfLifeDays());
    oraclecallablestatement.setString(38,getRestrictExpiredPick());
    oraclecallablestatement.setString(39,getArsRules());
    oraclecallablestatement.setString(40,getRestockOrdTgtOms());
    oraclecallablestatement.setString(41,getAttributeCategory());
    oraclecallablestatement.setString(42,getAttribute1());
    oraclecallablestatement.setString(43,getAttribute2());
    oraclecallablestatement.setString(44,getAttribute3());
    oraclecallablestatement.setString(45,getAttribute4());
    oraclecallablestatement.setString(46,getAttribute5());
    oraclecallablestatement.setString(47,getAttribute6());
    oraclecallablestatement.setString(48,getAttribute7());
    oraclecallablestatement.setString(49,getAttribute8());
    oraclecallablestatement.setString(50,getAttribute9());
    oraclecallablestatement.setString(51,getAttribute10());
    oraclecallablestatement.setString(52,getAttribute11());
    oraclecallablestatement.setString(53,getAttribute12());
    oraclecallablestatement.setString(54,getAttribute13());
    oraclecallablestatement.setString(55,getAttribute14());
    oraclecallablestatement.setString(56,getAttribute15());
    oraclecallablestatement.setString(57,getReferencename1());
    oraclecallablestatement.setString(58,getReferencename2());
    oraclecallablestatement.setString(59,getReferencename3());
    oraclecallablestatement.setString(60,getReferencename4());
    oraclecallablestatement.setString(61,getReferencename5());
    oraclecallablestatement.setString(62,getReferencename6());
    oraclecallablestatement.setString(63,getReferencename7());
    oraclecallablestatement.setString(64,getReferencename8());
    oraclecallablestatement.setString(65,getReferencename9());
    oraclecallablestatement.setString(66,getReferencename10());
    oraclecallablestatement.setString(67,getReferencename11());
    oraclecallablestatement.setString(68,getReferencename12());
    oraclecallablestatement.setString(69,getReferencename13());
    oraclecallablestatement.setString(70,getReferencename14());
    oraclecallablestatement.setString(71,getReferencename15());
    oraclecallablestatement.setString(72,getLnrefname1());
    oraclecallablestatement.setString(73,getLnrefname2());
    oraclecallablestatement.setString(74,getLnrefname3());
    oraclecallablestatement.setString(75,getLnrefname4());
    oraclecallablestatement.setString(76,getLnrefname5());
    oraclecallablestatement.setString(77,getLnrefname6());
    oraclecallablestatement.setString(78,getLnrefname7());
    oraclecallablestatement.setString(79,getLnrefname8());
    oraclecallablestatement.setString(80,getLnrefname9());
    oraclecallablestatement.setString(81,getLnrefname10());
    oraclecallablestatement.setString(82,getLnrefname11());
    oraclecallablestatement.setString(83,getLnrefname12());
    oraclecallablestatement.setString(84,getLnrefname13());
    oraclecallablestatement.setString(85,getLnrefname14());
    oraclecallablestatement.setString(86,getLnrefname15());
    oraclecallablestatement.execute();
    catch(SQLException sqlexception)
    throw OAException.wrapperException(sqlexception);
    catch(Exception exception)
    throw OAException.wrapperException(exception);
    }

  • Cannot get OUT parameter from stored procedure

    Hi,
    I am new to stored procedure programming. I wrote a simple java stored procedure as follows:
    package fvt;
    import java.sql.*;
    import java.io.*;
    public class FVTProcedures
    extends COM.ibm.db2.app.StoredProc {
    public void addRecord(int id, String name, int status)
    throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.Connection con = null;
    PrintWriter pw = null;
    try {
    status =3;
    pw = new PrintWriter(new FileWriter("c:/temp/fvtproc.txt"));
    pw.println("starting...");
    // get connection
    con =getConnection();
    pw.println("Got connection");
    stmt = con.createStatement();
    stmt.execute("INSERT INTO cmtest (id, name) values (" + id + ",'"+name+"')");
    pw.println("Inserted the record");
    if (!con.getAutoCommit()) {
    con.commit();
    pw.println("Committed the connection");
    catch (SQLException sqle) {
    pw.println(sqle.getMessage());
    catch (Exception e) {
    pw.println(e.getMessage());
    finally {
    status =2;
    pw.close();
    try {
    if (stmt != null) {
    stmt.close();
    catch (SQLException sqle) {}
    try {
    if (con != null) {
    con.close();
    catch (SQLException sqle) {}
    Then I use the following sql command to create this stored procedure, especially register status as OUT parameter.
    CREATE PROCEDURE addRecord (IN id INT, IN name VARCHAR(20), OUT status INTEGER)
    FENCED LANGUAGE JAVA EXTERNAL NAME 'fvt.FVTProcedures!addRecord' PARAMETER
    STYLE DB2GENERAL
    My java program calling this stored proc is as follows:
    import java.sql.*;
    import javax.sql.*;
    public class CallableStmtTest {
         COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource ds = null;
         public static void main(String args[]) {
              CallableStmtTest dt = new CallableStmtTest();
              try {
                   dt.test();
              } catch (Exception e) {
                   e.printStackTrace(System.out);
         public CallableStmtTest() {
              ds = new COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource();
              ds.setUser("username");
              ds.setPassword("password");
              ds.setDatabaseName("database");
    public void test() {
    java.sql.Connection conn = null;
    CallableStatement cs = null;
    String sql = "CALL ADDRECORD(?, ?, ?)" ;
    try {
    conn = ds.getPooledConnection().getConnection();
    conn.setAutoCommit(false);
    System.out.println("Got the connection");
    cs = conn.prepareCall( sql ) ; /* con is the connection */
    System.out.println("Callable statement is prepared");
    cs.registerOutParameter(3, java.sql.Types.INTEGER);
    cs.setInt(1, 1001 );
    cs.setString(2, "1001");
    cs.execute() ;
    System.out.println("Callable statement is executed, return status: "+cs.getInt(3));
    conn.commit();
    catch(SQLException sqle) {
    sqle.printStackTrace();
    finally {
    try {
    if (cs!=null) {cs.close();}
    catch (SQLException sqle1) {
    try {
    if (conn!=null) {conn.close();}
    catch (SQLException sqle1) {
    However, the out put is always
    Callable statement is executed, return status: 0
    while i expect to be
    Callable statement is executed, return status: 2
    Can anyone tell me what's wrong with that?
    thansk,
    JST

    public void addRecord(int id, String name, int status)
    throws SQLException {
    status =3;In regular java you are never going to see this value (3) outside of that method. Java doesn't work that way.
    So unless java inside the DB works really differently from regular java, you are going to have to pass something else.

  • Callable statement: out parameter type issue

    Hello again.
    My question is:
    how can I register the out parameter of a callable statement so that it may contain an oracle Cursor?
    Whether I register it to Types.OTHER (Types from the java.sql package) or OracleTypes.CURSOR (OracleTypes from the oracle.jdbc.driver package) it still says :
    PLS-00382: expression is of wrong type
    when trying to execute a statement that returns a cursor.
    I am using the com.sap.portals.jdbc.oracle package for the driver and such.
    If I change to use the oracle.jdbc.driver.OracleDriver and register the out parameter to OracleTypes.CURSOR, then it works.
    Thanks in advance,
    Silviu Lipovan Oanca
    Message was edited by: Silviu Lipovan Oanca

    more detailed
    1) i have write some java code using as usual my IDE:
    public class P141_JAVABridge
    public static void execute()
    String databaseDriver = "oracle.jdbc.driver.OracleDriver";
    String databaseUrl = "jdbc:oracle:thin:@xxx:1521:orcl";
    String databaseUsername = "xxx";
    String databasePassword = "xxx";
    ods.setDriverType(databaseDriver);
    ods.setURL(databaseUrl);
    ods.setUser(databaseUsername);
    ods.setPassword(databasePassword);
    connection = ods.getConnection();
    .... some code
    map.put("custom_T",Custom_T_SQLData.class);
    CallableStatement call = connection.prepareCall("call P141(?,?)");
    call.setObject(1,inputObjectReference);
    call.registerOutParameter(2,OracleTypes.STRUCT,"custom_T");
    call.execute();
    .... some code
    2) i run this code - wooha! it works
    3) i have changed
    connection = ods.getConnection();
    to
    connection = DriverManager.getConnection("jdbc:default:connection:");
    4) compile and load class into oracle
    5) i have linked P141_JAVABridge.execute() with P141_JB
    create or replace PROCEDURE P141_JB () IS LANGUAGE JAVA NAME 'x.y.z.P141_JAVABridge.execute()';
    6) then i executed P141_JB
    SET SERVEROUTPUT ON;
    BEGIN
    ...some code
    P141_JB();
    ...some code
    END;
    and got NullPointerException at
    ((Custom_T_SQLData)call.getObject(2)).responseStatus

  • Registering the out parameter

    how to register an out parameter in java which is of %rowtype in pl/sql procedure

    Hi,
    Which version of Weblogic and JDBC driver do you use?
    Regards,
    Slava Imeshev
    "chaat" <[email protected]> wrote in message
    news:3c02da3a$[email protected]..
    >
    Hi,
    I'm using weblogic-jdriver driver, on Invoking a stored procedure(which
    returns a Record) by registering the OUT parameter as
    callableStatement.registerOutParameter(1, Types.ARRAY);
    the code compiles, @run time gives the following exception..
    java.sql.SQLException: Unknown type: 2003
    Exception Object info ==>[[The error code = 0 and  sql state = null ]].
    Any insights are greatly appreciated.

  • Parameter name passed in Set Callable Statement

    Is it not possible to pass parameter name in the callable statement while using Oracle drivers for jk 1.4??
    Thanks!

    Is it not possible to pass parameter name in the callable statement while using Oracle drivers for jk 1.4??
    Thanks!

  • Cursor bound to out parameter with Connection Pool

    Is it possible to retrieve a cursor bound to an out parameter when using the thin
    driver to establish the connection pool to the database? I am currently using
    the JDriver to connect create the pool and the pool driver to connect from the
    app to the connection pool. We'd like to avoid using the Oracle client if possible.
    Currently I register the out parameter as java.sql.Types.OTHER, then call getResultSet(1)
    on the weblogic.jdbc.pool.CallableStatement object. But it breaks when I change
    the connection pool to use the thin driver. The error is at the bottom of this
    post.
    I think I could possibly get the current pool driver to work if can find some
    documentation on these two methods:
    void registerOutParameter(int i, int j, int k, int l)
    void registerOutParameter(int i, int sqlType, java.lang.String typeName)
    I have no idea what to put in for the ints in the first method or for sqlType
    or typeName. Can anyone point me to where I can find this documentation?
    E-docs mentions this class: weblogic.jdbc.vendor.oracle.OracleCallableStatement.
    (http://edocs.bea.com/wls/docs61/jdbc/thirdparty.html#1023867). Should I consider
    this? If so where is it?
    Thanks a lot,
    Matt Savino
    <<< error when using thin driver >>>
    preparing callable stmt
    callable stmt prepared, java.sql.Types.OTHER = 1111
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:4560)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:225)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:350)
    at weblogic.jdbc.pool.Statement.registerOutParameter(Statement.java:617)
    at jsp_servlet._reportmanager.__thin_outputresultset._jspService(__thin_outputresultset.java:145)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2390)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

    Thanks Joe, your answer pointed me in the right direction. Just in case anyone
    wants to know, the solution took two changes:
    CHANGE
    cStat.registerOutParameter(1, java.sql.Types.OTHER);
    TO
    cStat.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
    (cStat is an instance of weblogic.jdbc.pool.CallableStatement)
    AND
    rs = cStat.getResultSet(1);
    TO
    rs = cStat.getCursor(1);
    Thanks again,
    Matt
    Joseph Weinstein <[email protected]> wrote:
    Hi Matt.
    Look at the Oracle thin driver documentation to determine what type you
    should define in the registerOutParameter call. We use 'OTHER', but
    their driver may use something else for CURSOR output parameters.
    joe
    Matt Savino wrote:
    Is it possible to retrieve a cursor bound to an out parameter whenusing the thin
    driver to establish the connection pool to the database? I am currentlyusing
    the JDriver to connect create the pool and the pool driver to connectfrom the
    app to the connection pool. We'd like to avoid using the Oracle clientif possible.
    Currently I register the out parameter as java.sql.Types.OTHER, thencall getResultSet(1)
    on the weblogic.jdbc.pool.CallableStatement object. But it breaks whenI change
    the connection pool to use the thin driver. The error is at the bottomof this
    post.
    I think I could possibly get the current pool driver to work if canfind some
    documentation on these two methods:
    void registerOutParameter(int i, int j, int k, int l)
    void registerOutParameter(int i, int sqlType, java.lang.String typeName)
    I have no idea what to put in for the ints in the first method or forsqlType
    or typeName. Can anyone point me to where I can find this documentation?
    E-docs mentions this class: weblogic.jdbc.vendor.oracle.OracleCallableStatement.
    (http://edocs.bea.com/wls/docs61/jdbc/thirdparty.html#1023867). Should
    I consider
    this? If so where is it?
    Thanks a lot,
    Matt Savino
    <<< error when using thin driver >>>
    preparing callable stmt
    callable stmt prepared, java.sql.Types.OTHER = 1111
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:4560)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:225)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:350)
    at weblogic.jdbc.pool.Statement.registerOutParameter(Statement.java:617)
    at jsp_servlet._reportmanager.__thin_outputresultset._jspService(__thin_outputresultset.java:145)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:263)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2390)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1959)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    PS: Folks: BEA WebLogic is expanding rapidly, with both entry and advanced
    positions
    for people who want to work with Java, XML, SOAP and E-Commerce infrastructure
    products.
    We have jobs at Nashua NH, Liberty Corner NJ, San Francisco and San Jose
    CA.
    Send resumes to [email protected]

  • Errer when, Call from java to pl sql procedure with table out parameter

    Hi ,
    Please help me ? It's urgent for me .....
    My Oracle Code is like this ,
    CREATE TABLE TEST_TABLE ( DATE1 DATE, VALUE_EXAMPLE VARCHAR2(20 BYTE), VALUE2_EXAMPLE VARCHAR2(20 BYTE), VALUE3_EXAMPLE NUMBER ); CREATE OR REPLACE TYPE TONERECORDTEST AS OBJECT ( DATE1 DATE, VALUE_EXAMPLE VARCHAR2(20), VALUE2_EXAMPLE VARCHAR2(20), VALUE3_EXAMPLE NUMBER ); CREATE OR REPLACE TYPE TTESTTABLE IS TABLE OF TONERECORDTEST; CREATE OR REPLACE PACKAGE test_collection_procedures AS PROCEDURE testCallProcedureFromJava(start_time IN DATE, end_time IN DATE, table_data OUT TTesttable); END test_collection_procedures; / CREATE OR REPLACE PACKAGE BODY test_collection_procedures AS PROCEDURE testCallProcedureFromJava(start_time IN DATE, end_time IN DATE, table_data OUT TTesttable) IS BEGIN SELECT TONERECORDTEST(date1, value_example, value2_example, value3_example) BULK COLLECT INTO table_data FROM TEST_TABLE WHERE DATE1>=start_time AND DATE1<=end_time; END testCallProcedureFromJava; END test_collection_procedures;
    And my Java Code is like
    import java.sql.Connection; import java.sql.DriverManager; import oracle.jdbc.OracleCallableStatement; import oracle.jdbc.OracleTypes; import oracle.sql.ARRAY; import oracle.sql.ArrayDescriptor; import oracle.sql.STRUCT; import oracle.sql.StructDescriptor; public class testPLCollectionType { public static void main(java.lang.String[] args) { try{ //Load the driver Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@serverbd:1521:squema1","user", "password"); // First, declare the Object arrays that will store the data (for TONERECORDTEST OBJECT TYPE) Object [] p2recobj; Object [] p3recobj; Object [] p4recobj; // Declare the Object Arrays to hold the STRUCTS (for TTESTTABLE TYPE) Object [] p2arrobj; // Declare two descriptors, one for the ARRAY TYPE // and one for the OBJECT TYPE. StructDescriptor desc1=StructDescriptor.createDescriptor("TONERECORDTEST",conn); ArrayDescriptor desc2=ArrayDescriptor.createDescriptor("TTESTTABLE",conn); // Set up the ARRAY object. ARRAY p2arr; // Declare the callable statement. // This must be of type OracleCallableStatement. OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall("{call test_collection_procedures.testCallProcedureFromJa va(?,?,?)}"); // Declare IN parameters. Realize that are 2 DATE TYPE!!! Maybe your could change with setDATE ocs.setString(1,"01-JAN-04"); ocs.setString(2,"10-JAN-05"); // Register OUT parameter ocs.registerOutParameter(3,OracleTypes.ARRAY,"TTESTTABLE"); // Execute the procedure ocs.execute(); // Associate the returned arrays with the ARRAY objects. p2arr = ocs.getARRAY(3); // Get the data back into the data arrays. //p1arrobj = (Object [])p1arr.getArray(); p2arrobj = (Object [])p2arr.getArray(); System.out.println("Number of rows="+p2arrobj.length); System.out.println("Printing results..."); for (int i=0; i<p2arrobj.length; i++){ Object [] piarrobj = ((STRUCT)p2arrobj).getAttributes();
    System.out.println();
    System.out.print("Row "+i);
    for (int j=0; j<4; j++){
    System.out.print("|"+piarrobj[j]);
    }catch (Exception ex){
    System.out.println("Exception-->"+ex.getMessage());
    Actually when i running the java program it is showing error
    Exception-->ORA-06550: line 1, column 58:
    PLS-00103: Encountered the symbol "VA" when expecting one of the following:
    := . ( @ % ;
    The symbol ":=" was substituted for "VA" to continue.
      I am not getting the error .Please help me out Dhabas Edited by: Dhabas on Jan 12, 2009 3:49 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    // Declare the callable statement.
    // This must be of type OracleCallableStatement.
    ..."{call test_collection_procedures.testCallProcedureFromJa va(?,?,?)}");Looks like Ja divorced va.

  • Statement closed when using callable statements with oracle xe

    hi all, i've got this problem with oracle express edition 10g. I am using also oc4j v10.1.2.0.2. When working with a normal oracle database it was working fine (i think the code was the same, it's some time since i last tried, but you can see the code is very simple).
    So i just create a callable statement like this:
    CallableStatement cs = con.prepareCall(sentencia.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);
    and then when trying to access the statement to register an out parameter like this
    cs.registerOutParameter(1, parámetros[0].getTipo());
    it gives this error:
    java.sql.SQLException: Statement was closed
    It's puzzling me because, as i said before, i think the same code was working ok with a normal oracle database.
    Any idea what can it be?
    cheers

    Ah okay, sorry I've re-read your post.
    I believe you need to create a clob object that encapsulates your xml file.
    I've never done this but I would image it involves creating a class that implements the clob interface and passing an instantiation of this class to the callablestatement.
    Let me know how you get on.

  • Accessing a sys refcursor as a plsql out parameter

    The 11g jdbc guide gives and example of how to access a pl/sql function RETURNING a cursor. We have a stored proc that returns about 5 out parameters one of which is a SYS_REFCURSOR. This is different from RETURNING a ref cursor. Can someone please help me with how to pass a resultset object to the stored proc. I presume the same java declaration is required:
    ResultSet cursor;
    pass this as a parameter to the stored proc. I have listed the 11g JDBC sample code below:
    import oracle.jdbc.*;
    CallableStatement cstmt;
    ResultSet cursor;
    // Use a PL/SQL block to open the cursor
    ********** HIMANSHU reaplce this with the name of my stored proc dennis1.pkg_snapitall ****************
    cstmt = conn.prepareCall
    ("begin open ? for select ename from emp; end;");
    cstmt.registerOutParameter(1, OracleTypes.CURSOR);
    cstmt.execute();
    cursor = ((OracleCallableStatement)cstmt).getCursor(1);
    // Use the cursor like a standard ResultSet
    while (cursor.next ())
    {System.out.println (cursor.getString(1));}
    In the preceding example:
    •     A CallableStatement object is created by using the prepareCall method of the connection class.
    •     The callable statement implements a PL/SQL procedure that returns a REF CURSOR.
    •     As always, the output parameter of the callable statement must be registered to define its type. Use the type code OracleTypes.CURSOR for a REF CURSOR.
    •     The callable statement is run, returning the REF CURSOR.
    •     The CallableStatement object is cast to OracleCallableStatement to use the getCursor method, which is an Oracle extension to the standard JDBC API, and returns the REF CURSOR into a ResultSet object.

    public void readSysRef() throws SQLException {
    try {
    OracleCallableStatement stmt = (OracleCallableStatement)
    // both are ok.
    //NOTE: when using call, add ";" after get_empployees() will fail
    //connect.prepareCall("{ call ? := get_employees( ? ) }");
    connect.prepareCall("begin ? := get_employees( ? ); end;");
    stmt.registerOutParameter(1, OracleTypes.CURSOR);
    stmt.setInt( 2, 10000);
    stmt.execute();
    OracleResultSet rs = (OracleResultSet) stmt.getCursor(1);
    while (rs.next()) {
    System.out.format("Employee %1$s has salary %2$d.%n",
    rs.getString(1), rs.getInt(2));
    } catch (SQLException e) {
    throw e;
    }

  • Using A callable statement in java

    Hi all im trying to get results back from the database using a callable statement the problem is that it is placing / infront of single quotes.I need to get rid of this because it's not returning anything
    here is my code
    CallableStatement statementOne;
    statementOne = ComparitiveAnalysisGUI.conn.prepareCall("{call graphProc(?,?,?,?,?,?,?)}");
    statementOne.setString(1,"\"date_format(calldate, '%Y-%m-%d H:59:59'),avg(billsec)\"");
    statementOne.setString(2,"Clovercdr");
    statementOne.setString(3,start);
    statementOne.setString(4,end);
    statementOne.setString(5,"Boksburg");
    statementOne.setString(6,"\"billsec > 0 and Network = " + network + "\"");
    statementOne.setString(7,"\"date_format(calldate, '%Y-%m-%d %H:M:S')\"");
    System.out.println(statementOne.toString());
    rs = statementOne.executeQuery();
    the result of the println is
    com.mysql.jdbc.CallableStatement@ec4a87: CALL graphProc('"date_format(calldate, \'%Y-%m-%d %H:59:59\'),avg(billsec)"','Clovercdr','\'2006-03-14 00:00:01\'','\'2006-03-14 23:59:59\'','Boksburg','"billsec > 0 and Network = \'SAMobile\'"','"date_format(calldate, \'%Y-%m-%d %H:M:S\')"')
    as you can see quite a mess please help if you can get the statement to look as follows
    CALL graphProc("date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)",'Clovercdr','2006-03-14 00:00:01','2006-03-14 23:59:59','Boksburg',"billsec > 0 and Network = 'SAMobile'","date_format(calldate, '%Y-%m-%d %H:M:S')")
    thanks Brian

    Ok in order to understand why I did what I did parhaps it would be best if you saw my Stored procedure
    create procedure graphProc(col varchar(100),company varchar(20),startTime datetime,endTime datetime,branchName varchar(20),andSection varchar(200),groupSec varchar(100))
    BEGIN
    SET @stmt := CONCAT("SELECT ",col," from ",company," where calldate between '",startTime,"' and '",endTime,"' and branchName = '",branchName,"' and ",andSection," Group by ",groupSec);
    PREPARE stmt1 from @stmt;
    EXECUTE stmt1;
    the call is for example
    call graphProc("date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)",'Clovercdr','2006-03-01 00:00:01','2006-03-14 23:59:59','Boksburg',"billsec > 0 and date_format(calldate, '%k') BETWEEN 7 AND 19 and Network = 'SAMobile'","date_format(calldate, '%Y-%m-%d %H:M:S')")//
    as you can see In MySQL the "date_format(calldate, '%Y-%m-%d %H:59:59'),avg(billsec)" has to be quoted like this, so it can recognise it as a single parameter, since , '%Y-%m-%d %H:59:59' is viewed as another parameter
    thaks for your reply
    Brian

  • Return records from Stored Procedure to Callable Statement

    Hi All,
    I am createing a web application to display a students score card.
    I have written a stored procedure in oracle that accepts the student roll number as input and returns a set of records as output containing the students scoring back to the JSP page where it has to be put into a table format.
    how do i register the output type of "records" from the stored function in oracle in the "registerOutParameter" method of the "callable" statement in the JSP page.
    if not by this way is there any method using which a "stored function/procedure" returning "record(s)" to the jsp page called using "callable" statement be retrieved to be used in the page. let me know any method other that writing a query for the database in the JSP page itself.

    I have a question for you:
    If the stored procedure is doing nothing more than generating a set of results why are you even using one?
    You could create a view or write a simple query like you mentioned.
    If you're intent on going the stored procedure route, then I have a suggestion. Part of the JDBC 2.0 spec allows you to basically return an object from a CallableStatement. Its a little involved but can be done. An article that I ran across a while back really helped me to figure out how to do this. There URL to it is as follows:
    http://www.fawcette.com/archives/premier/mgznarch/javapro/2000/03mar00/bs0003/bs0003.asp
    Pay close attention to the last section of the article: Persistence of Structured Types.
    Here's some important snippets of code:
    String UDT_NAME = "SCHEMA_NAME.PRODUCT_TYPE_OBJ";
    cstmt.setLong(1, value1);
    cstmt.setLong(2, value2);
    cstmt.setLong(3, value3);
    // By updating the type map in the connection object
    // the Driver will be able to convert the array being returned
    // into an array of LikeProductsInfo[] objects.
    java.util.Map map = cstmt.getConnection().getTypeMap();
    map.put(UDT_NAME, ProductTypeObject.class);
    super.cstmt.registerOutParameter(4, java.sql.Types.STRUCT, UDT_NAME);
    * This is the class that is being mapped to the oracle object. 
    * There are two methods in the SQLData interface.
    public class ProductTypeObject implements java.sql.SQLData, java.io.Serializable
        * Implementation of method declared in the SQLData interface.  This method
        * is called by the JDBC driver when mapping the UDT, SCHEMA_NAME.Product_Type_Obj,
        * to this class.
        * The object being returned contains a slew of objects defined as tables,
        * these are retrieved as java.sql.Array objects.
         public void readSQL(SQLInput stream, String typeName) throws SQLException
            String[] value1 = (String[])stream.readArray().getArray();
            String[] value2 = (String[])stream.readArray().getArray();
         public void writeSQL(SQLOutput stream) throws SQLException
    }You'll also need to create Oracles Object. The specification for mine follows:
    TYPE Detail_Type IS TABLE OF VARCHAR2(1024);
    TYPE Product_Type_Obj AS OBJECT (
      value1  Detail_Type,
      value2 Detail_Type,
      value3 Detail_Type,
      value4 Detail_Type,
      value5 Detail_Type,
      value6 Detail_Type,
      value7 Detail_Type,
      value8 Detail_Type);Hope this helps,
    Zac

  • Using Refcursor in Callable Statement without using the Oracle Drivers

    Hello all,
    Is there anyway to have a stored procedure (Oracle 8i) return a refcursor to my CallableStatement without using the Oracle Thin drivers (i'm now using jdbcodbc). I've tried registering my out parameter with every possible type i can think of...REF, JAVA_OBJECT, OTHER, etc. but with no luck.
    Help!!!!

    Certainly...I connect to the database using the
    jdbcodbc driver and when i execute any of the code, i
    get the following error:
    java.sql.SQLException: [Oracle][ODBC][Ora]ORA-06550:
    line 1, column 7:
    PLS-00306: wrong number or types of arguments in call
    to 'PVISUAL_GET'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    It's bombing on the line that i attempt to register
    OracleTypes.CURSOR. It works fine when i use the
    oracle thin drivers, but i want to get this puppy
    working with the JdbcOdbcDriver. Here's the code:
    CallableStatement dbCall =
    nt dbCall =
    (CallableStatement)connection.prepareCall("{ call
    PAK_VISUAL_GET.pvisual_get(?, ?, ?, ?, ?, ?) }");
    dbCall.setString(1, sessionKey);
    dbCall.setInt(2,
    l.setInt(2, Integer.parseInt(storedVizID));
    dbCall.registerOutParameter(3,
    arameter(3, OracleTypes.CURSOR);
    dbCall.registerOutParameter(4,
    arameter(4, OracleTypes.NUMBER);
    dbCall.registerOutParameter(5,
    arameter(5, OracleTypes.VARCHAR);
    dbCall.registerOutParameter(6,
    arameter(6, OracleTypes.NUMBER);
    dbCall.execute();when you don't use oracle thin driver, you cannot use the OracleTypes. but, instead use the java.sql.Types values.Replace dbCall.registerOutParameter(3, OracleTypes.CURSOR); with
    dbCall.registerOutParameter(3,java.sql.Types.OTHER). things should be fine.
    Ganesh

  • Calling an Oracle stored procedure and retrieving result from OUT parameter

    Hello,
    I have a stored procedure that returns a string in an OUT parameter after receiving 6 IN parameters. I have tested the procedure in PL/SQL and it's producing the right output there. The problem is when I call the stored procedure from my Java method. I then get an error message telling me that I have the wrong number or types of arguments in my procedure call. I have checked that the method receives and sends the correct data in the correct order and I'm not sure what else the error message can relate to...?
    The exception is called on my second try statement but I haven't been able to find out what I have done wrong there. Does anyone have any suggestions? Thanks.
    the error message
    java.sql.SQLException: ORA-06550: line 1, column 13: PLS-00306: wrong number or types of arguments in call to 'P_SET_GIVEN_ANSWER' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
    the procedure
    CREATE OR REPLACE PROCEDURE p_set_given_answer(
    strfeedback OUT VARCHAR2,
    intpi_id IN INTEGER,
    intquestion_id IN INTEGER,
    intgivenanswer IN INTEGER,
    strgivenprefix IN VARCHAR2,
    strgivenunit IN VARCHAR2,
    strgu_id IN VARCHAR2) AS
    -- some declarations
    BEGIN
    -- some processing and then returns the string below indicating the outcome
    strfeedback = 'result';
    END
    the java method (the class is called dbUtil and the database connection is created in the method called getDbConnection() )
    public void setGivenAnswer(int intPi_id, int intQuestion_id, int intGivenAnswer, String strGu_id, String strGivenPrefix, String strGivenUnit) {
    java.sql.Connection con = null;
    String query = "{call ? := p_set_given_answer(?,?,?,?,?,?)}";
    try {
    con = dbUtil.getDbConnection();
    } catch(Exception e) {
    dbConnectionExceptionMessage = "error 1:"+e.toString();
    try{
    CallableStatement stmt = con.prepareCall(query);
    // register the type of the out param - an Oracle specific type
    stmt.registerOutParameter(1, OracleTypes.VARCHAR);
    // set the in params
    stmt.setInt(2, intPi_id);
    stmt.setInt(3, intQuestion_id);
    stmt.setInt(4, intGivenAnswer);
    stmt.setString(5, strGivenPrefix);
    stmt.setString(6, strGivenUnit);
    stmt.setString(7, strGu_id);
    // execute the stored procedure
    stmt.execute();
    // retrieve the results
    strFeedback = stmt.getString(1);
    } catch (java.sql.SQLException e) {
    dbConnectionExceptionMessage = "error 2:"+e.toString();
    try {
    con.close();
    } catch (java.sql.SQLException e) {
    dbConnectionExceptionMessage = "error 3:"+e.toString();
    ----------------------------------------

    Looks like you are declaring a procedure, but you are calling it like a function. A procedure has no return value, it has only parameters: "{call p_set_given_answer(?,?,?,?,?,?,?)}"

  • Callable statement problem-very urgent

    Hi Friends,
    i have 2 tables, in that two tables one column have same attribute column. when i update the first table through OAF page, i wanted to effect updated value in second table of that common field also. i wrote PL/SQL Procedure and called that into OAF by using callable statements. here first time i updated in the page, updated value is effecting into the first table while second table not effected the updated value. again i am trying to update the page this time in second table effected with first time updation value,while first table updated correctly. suppose i updated again in the page this time in second table effected with second time updation value, while first table updated correctly.this process continuing...
    example – I want to update forecast(this field is in two tables) value filed. Now forecast value is 10 in both tables , I updated as 20. this 20 updated value effected first table while second table forecast field is not effected.
    Again I am going to update value 30 in the place of 20. this 30 updated value effected first table while second table forecast field is 20(firstupdated value) effected.
    Again I am going to update value 40 in the place of 30. this 40 updated value effected first table while second table forecast field is 30(secondupdated value) effected this process continuing...
    Can any one help me out this problem
    This is I have written in AM-
    public void Callable()
    String forecast="";
    String name="";
    String product="";
    String business="";
    XXProgsVOImpl vo = getXXProgsVO1();
    RowSetIterator rowsetiterator=vo.getRowSetIterator();
    rowsetiterator.reset();
    while(rowsetiterator.hasNext())
    Row row = rowsetiterator.next();
    forecast=row.getAttribute("Forcast").toString();
    name=row.getAttribute("Name").toString();
    product=row.getAttribute("Product").toString();
    business=row.getAttribute("Business").toString();
    String s="BEGIN do_update(?,?,?,?);End;";
    OADBTransaction dbtrans=getOADBTransaction();
    OracleCallableStatement cs=(OracleCallableStatement)dbtrans.createCallableStatement(s,4);
    try
    cs.setString(1, forecast);
    cs.setString(2, name);
    cs.setString(3, product);
    cs.setString(4, business);
    cs.execute();
    dbtrans.commit();
    cs.close();
    catch(SQLException e)
    System.out.println(e.getMessage());
    Thanks and Regards,
    vamshi

    Hi Sumit and Thiago,
    Thanks for your information, my Both VO's are coming from EO'S. but first VO I have done some calculation on columns, that calulated value parameter passing to second page. this calculated value is the database column in second table. here when i update the calculated value in updated page , i want to effect this in second page table.
    do you have any work around this..
    Thanks and Regards,
    vamshi

Maybe you are looking for

  • Get all roles from an organization

    Hello, i want to get all roles 'AMRoles) from an organizations. I have Portal Server 2005Q4 on a machine and Access Manager and Directory on another and i want to extract all display profiles from all roles in different files (more than 100). I found

  • Web cam is not working for HP DV7

    I dont see the hardware or drivers for my WebCam it is not working and im not even sure it is installed anymore. I did not have a problem up until a few months ago not sure what happened. Can it be repaired?

  • Using the "IN" expression in SQL statement

    Hi, I have an array with multiple values stored in it. I would like to use these values in the filter expression of another query using the "IN" clause (data is coming from a sql dataabse). Is there a way to achieve this, I did not see an option in t

  • CHOOSE PRINTER

    Hi guys, I am creating an application with FORMS RUNTIME. Now, in one of my forms I need to create a button that pops up some kind of LOV or POPLIST or whatever it is, with the possible PRINTERS for the machine. Is there some sort of built in, ora an

  • Z3 Compact using mobile data even when disabled.

    Hey there, my new z3 compact is connecting to the mobile internet every 3 hours and causing costs! Mobile data is disabled in the setting and in the quick menu. WIFI is available all the time. In the settings it shows 0MB of volume for all apps. Besi