Java.sql exception for rs.nesxt() ( nested statements)

I have a problem with java.sql.I am getting an Invalid handle exception for nested result sets ...
example:-
//Conn is the common connection
Statement s1 = conn.createStatement();
rs1 = s1.executeQuery(query1);
while (rs.next){
Statement s2 = conn.createStatement();
rs2= s2.executeQuery(query2)
while (rs2.next){
The rs2 resultset works fine,but when it gets back into the outer while loop the exception is thrown.
I know that the problem is becuase the nested statements are usign the same connection.
I know of two ways to work around this
(1) use different connections
(2) remove nesting (save the result rs1,and then retrieve rs2)
But I wnated to know if anyone knows of any other way to work around this problem.
let me know.
Thanks.

Each connection has a single storage area for iteration, metadata, etc. Obviously you are aware that outer loop is unable to proceed because iteration data is of a different format from the inner sql query. It is not a good idea to do more than a single, or small set of queries on a single connection object. Would you consider a connection pool? They are not for the timid programmer, but they do take advantage of using connection objects much like pointers, with the ability to pop them into and out of a collection, ready to roll once the connection object is setup and ready for action much like a pointer that is properly assigned can be passed and always ready for action. The entire connection object (and metadata) is stored in the collection data structure. My advice is to keep it simple! It is easy to get too carried away with connection pools.

Similar Messages

  • Java.sql.SQLException: Unexpected token: IN in statement

    I use Toplink 2.0-b41-beta2 (03/30/2007) and have a problem with the following JPQL query:
    “SELECT DISTINCT OBJECT(e) FROM Entry e WHERE e.location IN (SELECT loc From View v JOIN v.viewLocs vl JOIN vl.location loc where v.code = :code)”
    “Entry” is a subclass of “TrainElement”, location points to Entity Location. Entity View has a one-to-many relationship to ViewLoc whereas each ViewLoc has a relationship to a Location object.
    Toplink creates the following incorrect sql statement – I inserted some CRLF for better readability::
    Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Unexpected token: IN in statement
    [SELECT DISTINCT t0.TELEM_TRAINELEM_ID, t0.TRAINELEMENT_TYPE, t0.TELEM_INDEX, t0.TTELEM_TRAIN_ID, t0.ENTRY_TYPE, t0.ENTRY_ARRIVAL, t0.DISPLAY, t0.ENTRY_ORDERED_STOP, t0.ENTRY_DEPARTURE, t0.ENTRY_ORDER_CODE, t0.ENTRY_PREV_SEC_ID, t0.ENTRY_NEXT_SEC_ID, t0.ENT_LOC_ID FROM TRAINELEMENT t0, LOCATION t1
    WHERE (( IN ((SELECT DISTINCT t2.LOC_ID, t2.LOC_GPSY, t2.LOC_GRX, t2.LOC_CODE, t2.LOC_GRY, t2.LOC_GPSX, t2.LOC_LOCAL_RADIO, t2.LOC_NAME, t2.DELETED, t2.LOC_CLASS_ID FROM VIEW t4, VIEWLOC t3, LOCATION t2 WHERE ((t4.VIEW_CODE = ?) AND ((t3.VIEWLOC_VIEW_ID = t4.VIEW_ID) AND (t2.LOC_ID = t3.VIEWLOC_LOCACTION_ID))))) AND (t0.TRAINELEMENT_TYPE = ?)) AND (t1.LOC_ID = t0.ENT_LOC_ID))]
    Error Code: -11
    Call: SELECT DISTINCT t0.TELEM_TRAINELEM_ID, t0.TRAINELEMENT_TYPE, t0.TELEM_INDEX, t0.TTELEM_TRAIN_ID, t0.ENTRY_TYPE, t0.ENTRY_ARRIVAL, t0.DISPLAY, t0.ENTRY_ORDERED_STOP, t0.ENTRY_DEPARTURE, t0.ENTRY_ORDER_CODE, t0.ENTRY_PREV_SEC_ID, t0.ENTRY_NEXT_SEC_ID, t0.ENT_LOC_ID FROM TRAINELEMENT t0, LOCATION t1 WHERE (( IN ((SELECT DISTINCT t2.LOC_ID, t2.LOC_GPSY, t2.LOC_GRX, t2.LOC_CODE, t2.LOC_GRY, t2.LOC_GPSX, t2.LOC_LOCAL_RADIO, t2.LOC_NAME, t2.DELETED, t2.LOC_CLASS_ID FROM VIEW t4, VIEWLOC t3, LOCATION t2 WHERE ((t4.VIEW_CODE = ?) AND ((t3.VIEWLOC_VIEW_ID = t4.VIEW_ID) AND (t2.LOC_ID = t3.VIEWLOC_LOCACTION_ID))))) AND (t0.TRAINELEMENT_TYPE = ?)) AND (t1.LOC_ID = t0.ENT_LOC_ID))
         bind => [ROMAN W-Pb, ENT]
    There sould be a “t0.ENT_LOC_ID” before the IN in the WHERE clause and the implicit join “ID FROM TRAINELEMENT t0, LOCATION t1” seems incorrect to me. At any rate the database (HSQLDB) rejects that incorrect sql statement.
    How can I circumvent that problem?
    A add the relevant mapping part of the involved classes.
    @Entity
    @DiscriminatorValue("ENT")
    public class Entry extends TrainElement implements IEntry {
         @ManyToOne(cascade = CascadeType.ALL)
         @JoinColumn(name = "ENT_LOC_ID", nullable = true)
         private Location location;
    @Entity
    @Table(name = "LOCATION")
    public class Location implements ILocation {
         // persistent part
         // primary key field
         @Id
         @GeneratedValue
         @Column(name = "LOC_ID")
         private Long id;
         @Column(name = "LOC_CODE", nullable = false)
         private String code;
         @Column(name = "LOC_NAME", nullable = false)
         private String name;
    @Entity
    @EntityListeners(EntityListener.class)
    @Table(name = "VIEW")
    public class View implements IView {
         // persistent
         // primary key field
         @Id
         @GeneratedValue
         @Column(name = "VIEW_ID")
         private Long id;
         @OneToMany(mappedBy = "view", cascade = CascadeType.ALL)
         private List<ViewLoc> viewLocs = new ArrayList<ViewLoc>();
    @Entity
    @Table(name = "VIEWLOC")
    @EntityListeners(EntityListener.class)
    public class ViewLoc implements IViewLoc {
         // persistent fields
         // primary key field
         @Id
         @GeneratedValue
         @Column(name = "VIEWLOC_ID")
         private Long id;
         @ManyToOne(cascade = CascadeType.ALL)
         @JoinColumn(name = "VIEWLOC_VIEW_ID", nullable = false)
         private View view;
         // direct Linking to the infrastrucutre location
         @ManyToOne(cascade = CascadeType.ALL)
         @JoinColumn(name = "VIEWLOC_LOCACTION_ID")
         private Location location;
    ….

    IN doesn't support objects, only state_field_path_expression that must have a string, numeric, or enum value.
    Try using
    “SELECT DISTINCT OBJECT(e) FROM Entry e WHERE e.location.id IN (SELECT loc.id From View v JOIN v.viewLocs vl JOIN vl.location loc where v.code = :code)”
    Best Regards,
    Chris

  • Error java.sql.exception when setting up repository for OWB 11g

    Hey all,
    I am encountering the following error on the last step of Repository Assistant, that is, while trying to set up the design repository in OWB 11g:
    "The Warehouse Builder workspace installation failed
    java.sql.SQLException : ORA-00942 table or view does not exist"
    Below is an excerpt from the the log file:
    main.TaskScheduler timer[5]20080620@14:51:54.054: 00> oracle.wh.service.impl.assistant.ProcessEngine.processSQLUserToken(ProcessEngine.java:1106)+>     at java.lang.Thread.run(Thread.java:595)
    main.TaskScheduler timer[5]20080620@14:51:54.054: 00> oracle.wh.service.impl.assistant.ProcessEngine.display(ProcessEngine.java:1572): Exception = java.sql.SQLException: ORA-00942: table or view does not exist
    main.TaskScheduler timer[5]20080620@14:51:54.054: 00> oracle.wh.ui.install.assistant.wizards.AssistantWizardDefinition.display(AssistantWizardDefinition.java:788): [executeOwbReposOrRuntime]: Error occurred during Workspace Installation. Exception =java.lang.Exception: java.sql.SQLException: ORA-00942: table or view does not exist
    main.AWT-EventQueue-0[6]20080620@14:51:54.054: 00> oracle.wh.ui.jcommon.WhButton@a22671: WhButton setLabel rtsString = OK
    main.AWT-EventQueue-0[6]20080620@14:58:17.017: 00> oracle.wh.ui.install.assistant.wizards.AssistantWizardDefinition.display(AssistantWizardDefinition.java:788): before open 'UnSuccessDialog'
    main.AWT-EventQueue-0[6]20080620@14:58:17.017: 00> oracle.wh.ui.install.assistant.wizards.AssistantWizardDefinition.display(AssistantWizardDefinition.java:788): Open UnSuccessDialog ...
    main.AWT-EventQueue-0[6]20080620@14:58:17.017: 00> oracle.wh.ui.jcommon.WhButton@a22671: WhButton setLabel rtsString = OK
    I am new to OWB so please let me know if I've left out any information that would help in figuring out why the installation is not completing.
    Thanks.

    The only thing I can think of in OWB 11g is that the main schema that is used, which is OWBSYS, wasn't fully installed or it doesn't have all the tables or views it needs or they weren't created properly with the cat_owb.sal script.
    Something must not have been created right. I would try to stop all OWB services with the appropriate scripts in:
    <your_owb_home>owb\rtp\sql
    try the stop_service.sql script.
    Then try to drop the users owbsys and whatever you might have created (if it exists) for a workspace owner user. Then clean up with:
    <your_owb_home>\owb\UnifiedRepos\clean_owbsys.sql
    After that it is back to the drawing board from the beginning. DO these steps again that you likely did in the first place:
    1. create owbsys with:
    <your_owb_home>\owb\UnifiedRepos\cat_owb.sql <tablespace_name>
    2. Set the control center home with:
    <your_owb_home>\owb\UnifiedRepos\reset_owbcc_home.sql <your_owb_home>
    *pay attention to the case of the the OWB HOME you give as a variable to the above script.  It needs to match the case of your real path.
    3. Finally unlock owbsys.
    4. look at <your_owb_home>\owb\bin\admin\ if the rtrepos.properties file size is at '0'. If it is for some reason, rename it to something else right now.
    5. Then try to run the repository assistant again.
    -Greg

  • How to capture the exact SQL exception for failure to connect to database

    Hi, i would like to capture the exact exception for failure to connect to a Oracle 9i database (via JDBC). I learnt that there is specific code or exception that can be captured, so that a more proper error message can be thrown out like "Failure to connect to database" can be displayed. Anyone know how to go about doing it? thanks

    That depends on your database vendor, I believe. (Unless there's a SQL standard for states and codes that I'm unaware of.)
    Personally, I wouldn't worry about "catching" a particular code. (You've already caught the exception - that's the best you can do.) I'd report the error code and state and just look up what it means when I got one.
    Hopefully you won't be catching exceptions. They're supposed to be rare. - MOD

  • How to throw or catch sql exception for executeReader sql adapter

    Wcf sql adapter was created and executeReader was used.
    When an invalid sql statement was constructed and send it to wcf sql adapter, it will hanging there, and no response. No exception was catched even though send chape  was inside a catch block. How can I catch this kind of exception
    or throw this exception ? I need to give client an exception resposne.
    thanks
    Gary

    I used scope with exception handle which has Exception object type: "System.SystemException".
    I guess this type "System.SystemException" can catch any exception, including sql exception. Maybe I am wrong. I got error from window event:
    A message sent to adapter "WCF-Custom" on send port "WcfSendPort_SqlAdapterBinding_DalCore_Custom" with URI "mssql://shig-quad-2k3e1//DataSourceOne?" is suspended.
     Error details: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
    Server stack trace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result)
       at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)
     MessageId:  {B24EF5B8-298A-4D4F-AA98-5E639361A7DB}
     InstanceID: {F8924129-265B-4652-B20E-8D25F8F20A51}
    If  "System.SystemException" can't catch all exception, which type can catch all exception ? I want to catch all exception in this catch block.
    thanks
    Gary

  • PL/SQL Exception for ORA-00942 - Table or view not found?

    Hey there!
    I want to create an exception my code runs into whenever it tries to select from a table that is not existent (or because of insufficient privileges).
    How can I get these ORA-00942 errors and place them into a exception? Except for WHEN OTHERS, that's not concrete enough.
    Regards,
    Thomas

    SQL> DECLARE
      2   table_not_found EXCEPTION;
      3   PRAGMA EXCEPTION_INIT(table_not_found, -942);
      4  BEGIN
      5   EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM DUALX';
      6  EXCEPTION
      7   WHEN table_not_found
      8   THEN
      9      dbms_output.put_line('Table NOT found');
    10  END;
    11  /
    Table NOT found

  • How can i import java.sql package for midlet development

    I am trying to write a midlet app using Wireless Toolkit 2.5.2. I would like to connect my application to JavaDB in embedded mode. But when I write "import java.sql.*;", I get an error "package java.sql does not exist
    ". I would like to know how can i include this package. please help.

    FBL wrote:
    Sorry to jump in, but isn't there limited jdbc using unconventional methods?
    [http://developers.sun.com/mobility/configurations/articles/cdc/jdbc/|http://developers.sun.com/mobility/configurations/articles/cdc/jdbc/]
    If so, I feel this may better answer the OPs question.
    -TresAbove article refers to CDC - it is useless in CLDC midlets

  • Java.NullPointer.Exception for UserUIConfig import

    Hi All,
    The moment I imported UserUIConfig.xml into IDM, my accounts page threw a java.NullPointer Exception.
    Does this file needs any tweaking to do a reimport?
    Any ideas would be appreciated.
    Thank You.
    G

    Crossposted:
    http://forum.java.sun.com/thread.jspa?threadID=5150105
    Would-be posters: Do not answer this thread. Go to the crosspost instead, where a discussion has already started.

  • SQL Query for real time resource stats

    Does anyone know what the query would be to duplicate the real time resource stats page in version 8 or above of UCCX?  I need to build a custom web page that displays the same information.  I've got all the connectivity to the database just fine and can query it and display information.  Just can't figure out what the SQL would be that would extract that information.

     Michael,
    you can try :
    SELECT x.resourceName, t.eventType, x.datetime FROM (SELECT t1.resourceID, t1.resourceName, MAX(t2.eventDateTime) AS datetime FROM Resource AS t1 INNER JOIN AgentStateDetail AS t2 ON t2.agentID = t1.resourceID GROUP BY t1.resourceID, t1.resourceName ) AS x INNER JOIN AgentStateDetail AS t ON t.agentID = x.resourceID AND t.eventDateTime = x.datetime ORDER BY x.resourceName
    You will need to translate the eventType into the "readable" status like Talking or Not Ready with an IF or Case statement.
    Regards,
    Jeroen

  • IFS Java SQL Exception during install.

    Hello,
    i just found an interesting error during installation process of Ifs. Be careful when you specify password
    for ifssys schema. I used a special character in password and an error occurred when ifssys schema creation started.

    Interesting, what special character did you use

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • MS SQL - sql type for Cursor

    Hello,
    Please help. I am using weblogic 8.1 and MS SQL Server 2000. Using JDBC. I have am calling a stored procedure which outputs a CURSOR. I haveing problems specifying the right java.sql.Type for this. I tried java.sql.Type.OTHER but it fails. The code is as follows
    I am planning to return more cursors from the Stored Procedures.
    ====
    Connection conn = null;
    CallableStatement stmt = null;
    String sqlProc = "{ call GetDocumentDetails(?,?) }";
    try {
    conn = this.getConnection();               
    stmt = conn.prepareCall(sqlProc);
    stmt.setInt(1, docId);
    stmt.registerOutParameter(2,Types.OTHER);
    stmt.execute();
    ResultSet rs = (ResultSet) stmt.getObject(2);
    while(rs.next()) {
    The exception that I get is
    java.sql.SQLException: [BEA][SQLServer JDBC Driver]The specified SQL type is not supported by this driver.
         at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
    PLEASE HELP.

    Hello,
    Please help. I am using weblogic 8.1 and MS SQL Server 2000. Using JDBC. I have am calling a stored procedure which outputs a CURSOR. I haveing problems specifying the right java.sql.Type for this. I tried java.sql.Type.OTHER but it fails. The code is as follows
    I am planning to return more cursors from the Stored Procedures.
    ====
    Connection conn = null;
    CallableStatement stmt = null;
    String sqlProc = "{ call GetDocumentDetails(?,?) }";
    try {
    conn = this.getConnection();               
    stmt = conn.prepareCall(sqlProc);
    stmt.setInt(1, docId);
    stmt.registerOutParameter(2,Types.OTHER);
    stmt.execute();
    ResultSet rs = (ResultSet) stmt.getObject(2);
    while(rs.next()) {
    The exception that I get is
    java.sql.SQLException: [BEA][SQLServer JDBC Driver]The specified SQL type is not supported by this driver.
         at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
    PLEASE HELP.

  • Java.sql.SQLException: ORA-08103: object no longer exists

    hi, Everyone:
    i want to insert one colume to a temp table,
    so i did the following
    1: drop the table
    2: recreate the table with the new colume in it.
    we i run my application, there is a
    "java sql exception ORA-08103: object no
    longer exists ". looks like the table
    doesn't exist in database any more. but
    it is really still there.
    thanks
    hongjie
    null

    I was able to resolve this error by using on commit preserve rows, instead of on commit delete.

  • Convert Calendar to Java.sql.Date

    I seached for a solution for converting a Calendar-object to a java.sql.date for inserting it into a MySQL DB (DateTime). I know this question is a FAQ. The solution I found is the following code:
    java.sql.Date sqlDate =  new java.sql.Date(cal.getTime().getTime() );When i do a print of the sqlDate to the console I get: sqlDate: 2005-06-27
    But when I look into de DB I get the following date: 27/05/1905
    I know that in Java the months are starting from 0-�11 and that the years counting is starting from 1900. But I assume that the solution is not to just add the correct month and year manually. because I get a correct console-output. If I do this I get a correct DB Date, but a wrong console-date.

    II dont know if you found an answer but I needed a similar solution so I wrote a test program.
    Let me know if this solves the problem for you.
    import java.util.*;
    import java.sql.*;
    public class dateTest{
    public static void main(String args[]){
    // Step by step
    // Calendar rightNow = Calendar.getInstance();
    // java.util.Date today = rightNow.getTime();
    // long theTime = today.getTime();
    // java.sql.Date sDate = new java.sql.Date(theTime);
    // In one line
    java.sql.Date sDate = new java.sql.Date(Calendar.getInstance().getTime().getTime());
    System.out.println("sDate is: "+sDate.toString());
    }

  • Java.sql.PreparedStatement#setUnicodeStream deprecated

    Hi all!
    The method setUnicodeStream of java.sql.PreparedStatement is set to deprecated without any comment since at least J2SE 1.3.1. Does anybody know what's the reason? Is there any alternative?
    Thanks in advance
    Carsten

    I've got a java.sql.date that I need to put into a
    calendar object. I was planning to use
    Calendar.set(date.getYear(), date.getMonth(),
    date.getDay()) but these methods are all deprecated
    now. Do I have to do date.toString() first, then
    parse out each value? This seems like a waste to me.
    btw - we use java.sql.date for our DB dates.What about Calendar.setTime(Date date)?

Maybe you are looking for

  • Closed Auto Loan Reporting As Open Question

    I have an auto loan reporting across all bureaus as open but in good standing. I suppose that is well and good except for the fact that the loan was closed in Dec of last year. My question...would having the loan shown as open reduce my credit score

  • Is Apple Pro Res viewable on computers WITHOUT Final Cut installed?

    I have used Apple Pro Res to compress 3d animation and it looks great, far better than any codec so far. Now I find that it is only viewable on computers with Final Cut Pro 6 installed. I am planning to exhibit the work as quicktimes, but need to use

  • JSTL 1.0 unterminated tag

    I am new to java web development so please bear with me. Can someone please tell me why I get a jsp.error.unterminated tag exception from the following snippet: <portlet:param name="event.id" value="<c:out: value="${evntContainer.event.id}"/>"/>I am

  • Printing problems in black & white

    I have an HP3180 all in one printer which wont copy or print in black & white for photos. It prints txt fine but photos come out purple/ new black ink cartrige. Please help

  • SAP OIL AND GAS Certification.

    Hello Consultants, Im working as an SAP FICO Consultant with double certification having an experience of 3+ years in Gulf Countries. Im planning for SAP Oil & Gas UPSTREAM Certification. I would like to have proper guidance from SAP Gurus regarding