Caching of Prepared and Callable Statements

A Prepared Statement object represents a precompiled SQL statement.
Where is this precompiled SQL statement stored, in the database?
What happens when this object goes out of scope / garabage collected?
Using the WebLogic App. Server's console, we can set the size and type of the Statement Cache. So does that mean even after the Prepared Statement object going out of scope, the precompiled SQL it had represented is still available in the database ?

Read this thread
http://forum.java.sun.com/thread.jspa?threadID=692297
It will answer your queries and much more too. :)

Similar Messages

  • Statement,Prepared Statement and callable statement

    Hi,
    Please let me know in which scenario we are using Statement,Prepared Statement and callable statement.
    and which is efficient one among the above.
    Thanks in advance

    Welcome to the forum!
    >
    Please let me know in which scenario we are using Statement,Prepared Statement and callable statement.
    >
    We don't know what scenario you are using those in or if you are using them at all. Are you asking what they are?
    For document related questions you should consult the documentation or use your favorite search engine to get information.
    See the Java Tutorial
    http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
    >
    The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created. The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled. As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first.
    >
    The Javadocs for your Java SDK have the API for each of those classes and a description of what they are. And the Oracle JDBC Developer Guide has extensive information on how to use them.
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/toc.htm

  • Weblogic7.0 with MS SQL Server 2000 and Callable Statement

    Hello,
    we have a little problem with our weblogic application.
    In the SQL Server we have written a simple stored procedure
    CREATE PROCEDURE nextval
    @sequence_id INT OUT
    AS
    -- return an error if sequence does not exist
    -- so we will know if someone truncates the table
    set @sequence_id = -1
    UPDATE sequences
    SET @sequence_id = sequence_id = sequence_id + 1
    RETURN @sequence_id
    GO
    It's a simple pk generator.
    Also we have written a simple java application to test this procedure (getting
    the connection over the weblogic datasource) and everything works fine.
    But in the application running on weblogic we have problems with the second call.
    Here the exceptions:
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn vor = null
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn nach = weblogic.jdbc.rmi.SerialConnection@397317
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal prepareCall
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal set gina
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal registeredOUtparameter
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal execute = false
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal nextVal = 30037
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn vor = null
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn nach = weblogic.jdbc.rmi.SerialConnection@4377a3
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal prepareCall
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal set gina
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal registeredOUtparameter
    03.09.2002 / 14:33:24: [LOGLEVEL: 0] PKGenerator.nextVal execute = false
    03.09.2002 / 14:33:24: [LOGLEVEL: 0] ****** PKGenerator.nextVal SQLException =
    java.sql.SQLException: The transaction is no longer active (status = Rolling Back.
    [Reason=weblogic.transaction.internal.TimedOutException: Transaction timed out
    after 29 seconds
    Name=[EJB de.fiatbank.vehicle.template.beans.TemplateDetailEJB.create(java.util.ArrayList,java.util.ArrayList,java.util.ArrayList,java.lang.String)],Xid=220:408eb51e3b228e43(691834),Status=Active,numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds
    since begin=29,seconds left=30,activeThread=Thread[ExecuteThread: '14' for queue:
    'default',5,Thread Group for Queue: 'default'],ServerResourceInfo[weblogic.jdbc.jts.Connection]=(state=started,assigned=none,xar=weblogic.jdbc.jts.Connection@ffb40),SCInfo[fiatbank+gina]=(state=active),properties=({weblogic.transaction.name=[EJB
    de.fiatbank.vehicle.template.beans.TemplateDetailEJB.create(java.util.ArrayList,java.util.ArrayList,java.util.ArrayList,java.lang.String)],
    weblogic.jdbc=t3://192.168.0.27:7001, LOCAL_ENTITY_TX=true}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=gina+192.168.0.27:7001+fiatbank+t3+,
    Resources={})],CoordinatorURL=gina+192.168.0.27:7001+fiatbank+t3+)]). No further
    JDBC access is allowed within this transaction.
    the two files are:
    PKGenerator.java (Weblogic application)
    CallableSamples1.java (TestApplication)
    Has anyone an idea, if weblogic has a problem or we have made a mistake?
    Bye
    Steffen
    [files.zip]

    Steffen Schenk wrote:
    Hello,
    we have a little problem with our weblogic application.Hi. It's not a JDBC issue, it's an EJB/transaction coordinator issue.
    Any transactional EJB JDBC is done under the (usually silent) control of the
    transaction coordinator. For instance, if your code calls Connection.commit()
    in a transactional EJB, it will cheerfully be ignored, because only the transaction
    coordinator knows when and whether to commit the whole transaction, not the
    individual EJB, which may have been called as part of a larger transaction. Another
    aspect of the coordinator's overseeing of the transaction is that once the transaction
    is over, which may be right in the middle of an EJB's running if the transaction
    timeout limit has been reached, then the coordinator will roll back or commit the
    transaction as appropriate and take control of the JDBC objects. Any further attempt
    by the EJB to do any JDBC will result in an exception.
    >
    In the SQL Server we have written a simple stored procedure
    CREATE PROCEDURE nextval
    @sequence_id INT OUT
    AS
    -- return an error if sequence does not exist
    -- so we will know if someone truncates the table
    set @sequence_id = -1
    UPDATE sequences
    SET @sequence_id = sequence_id = sequence_id + 1
    RETURN @sequence_id
    GO
    It's a simple pk generator.
    Also we have written a simple java application to test this procedure (getting
    the connection over the weblogic datasource) and everything works fine.
    But in the application running on weblogic we have problems with the second call.
    Here the exceptions:
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn vor = null
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn nach = weblogic.jdbc.rmi.SerialConnection@397317
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal prepareCall
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal set gina
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal registeredOUtparameter
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal execute = false
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal nextVal = 30037
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn vor = null
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal conn nach = weblogic.jdbc.rmi.SerialConnection@4377a3
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal prepareCall
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal set gina
    03.09.2002 / 14:32:45: [LOGLEVEL: 0] PKGenerator.nextVal registeredOUtparameter
    03.09.2002 / 14:33:24: [LOGLEVEL: 0] PKGenerator.nextVal execute = false
    03.09.2002 / 14:33:24: [LOGLEVEL: 0] ****** PKGenerator.nextVal SQLException =
    java.sql.SQLException: The transaction is no longer active (status = Rolling Back.
    [Reason=weblogic.transaction.internal.TimedOutException: Transaction timed out
    after 29 seconds
    Name=[EJB de.fiatbank.vehicle.template.beans.TemplateDetailEJB.create(java.util.ArrayList,java.util.ArrayList,java.util.ArrayList,java.lang.String)],Xid=220:408eb51e3b228e43(691834),Status=Active,numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds
    since begin=29,seconds left=30,activeThread=Thread[ExecuteThread: '14' for queue:
    'default',5,Thread Group for Queue: 'default'],ServerResourceInfo[weblogic.jdbc.jts.Connection]=(state=started,assigned=none,xar=weblogic.jdbc.jts.Connection@ffb40),SCInfo[fiatbank+gina]=(state=active),properties=({weblogic.transaction.name=[EJB
    de.fiatbank.vehicle.template.beans.TemplateDetailEJB.create(java.util.ArrayList,java.util.ArrayList,java.util.ArrayList,java.lang.String)],
    weblogic.jdbc=t3://192.168.0.27:7001, LOCAL_ENTITY_TX=true}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=gina+192.168.0.27:7001+fiatbank+t3+,
    Resources={})],CoordinatorURL=gina+192.168.0.27:7001+fiatbank+t3+)]). No further
    JDBC access is allowed within this transaction.
    the two files are:
    PKGenerator.java (Weblogic application)
    CallableSamples1.java (TestApplication)
    Has anyone an idea, if weblogic has a problem or we have made a mistake?
    Bye
    Steffen
    Name: files.zip
    files.zip Type: Zip Compressed Data (application/x-zip-compressed)
    Encoding: base64

  • Is there a difference between Statement Cache and the statement handle!

    Hello!
    The OCI statement cache is !session! wide. When I have a sql statement that was used before, I can use this feature.
    But what is the difference between this feature and my statement handle for a certain sql statement that I can store and reuse a second time?
    My stored statement handle is already prepared and the placeholders are bound. The second time I only have to copy new values in the memory positions and do an execute and that's all.
    Thank you in advance
    Wolfgang

    The underlying optimization is the same. When you re-execute a statement, you are reusing the metadata already available in the statement and the cursor already open on the server. If you know exactly the set of statements that you are going to execute repeatedly, you can maintain the cache on your own. (Yes, you save on doing the Bind/Define calls multiple times).
    OCI Statement cache makes it transparent and the application does not need to keep the references/indexes to the relevant statements. Also once a cache size is set, least recently used statements get out of the cache when the cache is full and needs to accommodate more.
    To optimize the bind/defines on the statements from the statement cache, you can use this feature:
    http://www.filibeto.org/sun/lib/nonsun/oracle/11.2.0.1.0/E11882_01/appdev.112/e10646/oci09adv.htm#sthref1358

  • Callable statements and cursors in database

    Hi,
    I am using a callable statement (from a JSP) that calls a big stored oracle procedue. The stored procedure inserts/deletes/updates many tables.
    But once i close the statement(I am sure i closed it in finally block), when i monitor the database, there are a lot of cursors open,one cursor for every insert/update/select statement in the procedure.
    But when i hit the same JSP again, it is not opening more cursors, but reusing them. But when multiple users hit the page simultaneously, it is opening more cursors and we could find that it is a multiple of number of active connections.
    Is this a feature (statement cachin??). we can understand if it opens one cursor per procedure. But if we have tens of selects/updates in a procedure, why should it open that many number of cursors?
    I need to set the number of open cursors in oracle to a big number for this. Will it eat up my resources?
    software
    9ias containers 9.0.3
    oracle 9i database
    Thanks
    Srinath

    ...callable statement to pass ...Are you perhaps explicitly writing code to replace a single tick with two single ticks. And also using the setString() method? If so each single tick would then become four ticks in the insert, which would be stored as two ticks. And then when you query it out you would have two ticks.

  • 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

  • Callable Statement wot working properly

    I have a situation where using CallableStatement only executes the stored proc intermittenly,
    while utilizing Statement works all the time. This didn't happen under WLS 5.1 SP
    6. Does anyone else have the same problems.
    Also in both cases the jdbc log produces the following message:
    SQLWarning: reason(010P4: An output parameter was received and ignored.) SQLState(010P4)
    But we have nothing being returned from the stored proc and no OUT parameters.
    We are using Jconnect native jdbc drivers with Sybase 11.9.2
    Thanks a lot, Alex

    Lev wrote:
    We are using WebLogic 7.0 and we downloaded the latest version
    of Sybase Driver. Previously we used WebLogic 5.1 sp 9 and
    excatly the same sybase driver and code and it worked.Yes. The change in our code is that we now cache PreparedStatements
    with their pooled connections, and when a pool connection is re-used,
    if the requestor prepares a statement with the same parameters including the SQL,
    as before, they get a cached statement which has had it's prior arguments cleared.
    This is a big performance win, but it has had the side effect of revealing bugs
    in various JDBC drivers when statements are re-used for an indefinite period
    of time.
    As I said, the first thing to do is to stop the symptoms, byt setting the cache size
    to 0, to stop us caching. If you are willing to help us debug the driver, the test would
    be a standlaone program that used the sybase driver to make a connection and
    prepare a statement like your code uses, then run a long-running loop that
    sets the arguments, executes the statement, calls clearParameters(), and repeats.
    This duplicates what we make the driver do, and should eventually demonstrate
    the driver bug. Is there any chance that the same prepared statement is being
    used in different ways, such that the same SQL is used for a CallableStatement
    getting back output parameters (even just the procedure status) sometimes, and
    as a PreparedStatement other times?
    Joe
    >
    >
    Joseph Weinstein <[email protected]> wrote:
    Alex wrote:
    Joeseph,
    We had jconn2.jar in front of weblogic classpath all the time
    and it does not help.make sure it's the latest.
    We are about to open a case with WebLogic.
    Could you please help us ASAP.Understood. What version of the server are you running now? The first
    step is to avoid the sybase driver problem by turning off our statement
    cache.
    Thanks, Alex
    Joseph Weinstein <[email protected]> wrote:
    >
    Hi. This probably has to do with our caching of prepared statements and
    a bug in the version of the sybase driver that we ship. Please download
    sybase's latest driver and put it ahead of all weblogic stuff in the
    server
    classpath, and let me know...
    Joe
    "Alex" <[email protected]> wrote in message
    news:[email protected]...
    I have a situation where using CallableStatement only executes the
    stored
    proc intermittenly,
    while utilizing Statement works all the time. This didn't happen
    under
    WLS
    5.1 SP
    6. Does anyone else have the same problems.
    Also in both cases the jdbc log produces the following message:
    SQLWarning: reason(010P4: An output parameter was received and ignored.)SQLState(010P4)
    But we have nothing being returned from the stored proc and no OUTparameters.
    We are using Jconnect native jdbc drivers with Sybase 11.9.2
    Thanks a lot, Alex

  • How to return Multiple ResultSets Using Callable Statement

    hi everybody,
    while i was working with callable statements i came across a problem of how to fetch Multiple Resultsets by means of Stored Procedures written for tables in Oracle.
    If any one can help me, pls do help me with a detailed explanation, and if possible do get me a example source code too.
    khumaar

    I have a similar problem with oracle and jdbc:
    I want to send a sql query like:
    sqlQuery = "select n1, n2 from table1; select n1, n2
    from table2"
    I used a prepared statement, but when I call
    .execute(sqlQuery)
    oracle doesn't like this,
    can someone help on this?Try putting a begin/end around it. Play with the syntax first in sqlplus.
    You do realize that you MUST extract using the syntax for extracting multiple result sets correct? It will NOT work as one result set.

  • 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

  • How to get the returned value from Functions with Callable statement?

    I was glad to find that stored procedures can be invoke with Java class code by the object of Callable statement like :
    String stmt = "BEGIN departments_pkg.do_select(?,?,?); END;";
    and getting the output variables by
    populateAttribute(DEPARTMENTNAME,st.getString(2),true,false);
    But i would like to get values returned from FUNCTION other than stored procedure, how can i achieve it? Thanks a lot!

    Here is  my code
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_1202.
      MODULE subscreen_find.
      CALL SUBSCREEN SUBSEARCH INCLUDING sy-cprog dynnr.
    PROCESS AFTER INPUT.
      MODULE USER_COMMAND_1202.
      CALL SUBSCREEN SUBSEARCH.
    MODULE subscreen_find.
      case sy-ucomm.
        when 'SELECTED'.             "fcode
          case 'ZSKILL_SEARCH'.     "data element
            when '01'.                       " value range
              dynnr = 0110.
            when '02'.
              dynnr = 0111.
          endcase.
      endcase.
    ENDMODULE.
    kindly tell me what is wrong
    Edited by: Raji Thomas on Feb 8, 2010 10:20 AM

  • Please, Not getting result set from callable statement (Code posted)

    I am posting some simple code which should get a ResultSet from a CallableStatement object using the executeQuery() Method.
    It is returning "No RsultSet was produced"
    If I modify the code and simply output the CallableableStatement using its executeUpdate() then getString() methods it works fine. Anything obviously wrong with this bit of code? Thanks.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import db.util.query.*;
    import db.util.pool.*;
    public class oracle extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    Connection con = ConnectionFactory.getConnection();
    CallableStatement cs = null;
    ResultSet rs = null;
    int intID = 1;
    try{
    cs = con.prepareCall("{? = call test1(?)}");
    cs.registerOutParameter(1, java.sql.Types.VARCHAR);
    cs.setInt(2,intID);
    /*These lines work on their own
    *cs.executeUpdate();
    *out.println("Name is : " + cs.getString(1));
    //this code is what is not working...hmm
    rs = cs.executeQuery();
    while(rs.next()){
    out.println(rs.getString("name"));
    rs.close();
    cs.close();
    //the rest of this works too.
    ConnectionFactory.releaseConnection(con);
    catch(SQLException e){
    out.println(e.getMessage());
    Here's the stored procedure. I'm just trying to do a simple test to return multiple rows. The table has numberous records with the same id which is being passed to the function.
    create or replace function test1 ( strInputID IN testtable.id%type)
    return varchar2
    is
    strOutputName testtable.name%type;
    found_it EXCEPTION;
    begin
    select name into strOutputName from testtable
    where id = strInputID;
    raise found_it;
    exception
    when no_data_found
    then
    return null;
    when found_it
    then
    return strOutputName;
    end;

    I've posted the code...it's doing a select. I think the problem is that to return multiple rows I need to return a cursor. But I've run into problems with both the MS and Oracle Drivers.
    All I really want to do is to query a database using a callable statement(function in oracle) which will return multiple rows which I can process. I have been trying to do this in a servlet.
    I can do it successfully for one column from one row, but not multiple columns from mulitple rows.
    I've been searchging for some good examples and am trying different things but can't seem to get it to work.

  • How to pass Array of Java objects to Callable statement

    Hi ,
    I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
    So I am having and array list of some object say xyz which has two attributes string and double type.
    Now I need to pass this to a PL/SQL Procedure as IN parameter.
    Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
    And we will use a record type from SQL to map this to our array of java objects.
    So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
    Please help
    Thanks

    I seem to remember that that is in one of Oracle's online sample programs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

  • How it works (Calling Stored Procedure in DB2 Through Callable statement)

    Can anyone Please tell me what exactly happens on calling ESP(External Stored Procedure) through Callable statement Database point of view and Callable point of view also.
    eg:
    CallableStatement cstmt = con.prepareCall(
    "{call getTestData(?, ?)}");
    cstmt .executeUpdate();
    where getTestData is Stored Procedure in DB2.
    Can anyone please guide me working on this scenario..
    Message was edited by:
    Nitin_Gupta

    Check this post out:
    http://forum.java.sun.com/thread.jspa?threadID=638768&messageID=3785982
    But I think you should be getting results right? What do you mean you want it in a format other than resultset?

  • Error executing a callable statement on a pooled connection

    Hi,
    I have an Oracle function that returns a number:
    create or replace function
    S2B_STOP_STAGE (DOC_ID number, ST_ID number)
    return number ...
    and the following Java code:
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:madrigalPool");
    String sql = "{? = call S2B_STOP_STAGE(401,1002)}";
    CallableStatement stmt = conn.prepareCall(sql);
    stmt.registerOutParameter(1, Types.INTEGER);
    stmt.execute(sql);
    res = stmt.getInt(1);
    When the execute(sql) statement is executed, a SQLException is thrown:
    java.sql.SQLException: ORA-01008: not all variables bound
    at weblogic.jdbc.pool.PreparedStatement.execute(PreparedStatement.java:121)
    Does anybody have an idea about what may be wrong? I am using Oracle
    8.1.6, the thin driver classes12-81620.zip, and WebLogic 6.0 sp2.
    Thanks,
    Vladimir

    I found out what was wrong. I should have used execute() instead of execute(sql)
    on the callable statement...
    Sorry for the problem.
    Vladimir
    "vladimir" <[email protected]> wrote:
    >
    Hi,
    I have an Oracle function that returns a number:
    create or replace function
    S2B_STOP_STAGE (DOC_ID number, ST_ID number)
    return number ...
    and the following Java code:
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:madrigalPool");
    String sql = "{? = call S2B_STOP_STAGE(401,1002)}";
    CallableStatement stmt = conn.prepareCall(sql);
    stmt.registerOutParameter(1, Types.INTEGER);
    stmt.execute(sql);
    res = stmt.getInt(1);
    When the execute(sql) statement is executed, a SQLException is thrown:
    java.sql.SQLException: ORA-01008: not all variables bound
    at weblogic.jdbc.pool.PreparedStatement.execute(PreparedStatement.java:121)
    Does anybody have an idea about what may be wrong? I am using Oracle
    8.1.6, the thin driver classes12-81620.zip, and WebLogic 6.0 sp2.
    Thanks,
    Vladimir

  • 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.

Maybe you are looking for

  • Billing date comes later than PGI Date

    Dear Friends For a particular customer, billing date is getting generated two days after the PGI date. But for all other customers we are getting billing date on the same date as PGI is done. This problem is occurred soon after we have started invoic

  • APO DP and SNP planning

    Hi friends, please send me any links related to APO DP and SNP planning on sales. Message was edited by:         siri raj

  • Can I shut off auto-correct when typing text messages

    When I am typing a text message, my phone auto corrects.  Is there a way to shut this feature off?

  • Why doesn't my linksys router work with my airport express?  I can't print!

    I can't print to my hp photosmart 1315 with my airport connected to my linksys router. I can only print directly with USB. I had the airport express tested at the apple store and it worked fine with my printer, but now at home, on hte linksys wireles

  • Fastweb e server lenti

    Fastweb fibra 100 regoalrmente testata e funzionante lentezza avvilente sui server Apple! Buonasera da più di un giorno inspiegabilmente ho 3 dispositivi su 4 Apple bloccati, perché impossibile aggiornare il software perché la lentezza per scaricare