Results 1 to 6 of 6

Thread: Hi

  1. #1
    Join Date
    Jul 2002
    Posts
    19

    Unanswered: Hi

    Hi,
    I am using DB2 V 8.1 on win NT and I am running my JDBC application. I am creating statement using connection and then I am running a query executeUPdate(query). When I execute this statement it hangs and I also got an error saying statement is not valid or close. How is that possible ? I have debugged the code several times in VAJ. When i create statement connection gives a valid statement.

    could someone tell me its bug or some problem in my code ?

    regards,
    ajay
    Thanks,
    Ajay

  2. #2
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    Please send more info about your system and the code you are trying to execute and the error message.

    Please also read Must Read before posting for tips how to ask efficient question.

    Hope this helps,
    Gorfaty

  3. #3
    Join Date
    Jul 2002
    Posts
    19

    JDBC Statement invalid/close

    Hi,
    I am using DB2 version 8.1 without any fixpack on win NT 4. My application is multithreaded and I interact with DB2 using JDBC. My application is server kind of thing which always in a running state. When I start my server and execute following code it runs fine and when this method called again it hangs at s.executeUpdate. I have debugged my code, connection returns a valid statement but still it hangs. I tried to debugg this scenario several times and few times in VAJ i am able to find the exception also.
    ConnectionFactory is a pool which maintains the connections.

    I have posted my code, State of the statement and Exception also.

    My Code:

    public void runDML(String _sql) throws Exception
    {

    Connection conn = ConnectionFactory.getConnection(this.dbName);

    Statement s = conn.createStatement();

    System.out.println("Executing DML statement:");
    System.out.println(_sql);

    try {
    s.executeUpdate(_sql);


    }catch(Exception e) {

    if(!e.getMessage().equalsIgnoreCase("No data found"))
    throw e;

    }finally {

    s.close();
    conn.close();

    }
    }

    Statement S before calling s.executeUpdate();

    DB2Statement
    {
    Connection -> DB2Connection
    Connection -> {
    Connection -> connectionHandle = 1
    Connection -> SPConnected = false
    Connection -> source = PolicyDB
    Connection -> user = db2admin
    Connection -> conArgs =
    Connection -> closed = false
    Connection -> describeCached = false
    Connection -> describeParam = true
    Connection -> isReadOnly = false
    Connection -> autoClose = false
    Connection -> LONGDATA compat = false
    Connection -> }

    ResultSet -> null

    statementHandle = 1:2
    SQL = null
    maxRows = 0
    maxFieldSize = 0
    rowCount = 0
    colCount = 0
    closed = false
    internalStmt = false
    returnCode = 0
    }


    Exception:

    COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver]
    | CLI0601E Invalid statement handle or statement is closed.
    | SQLSTATE=S1000


    If any other information is required pls let me know.

    Regards,
    Ajay
    Thanks,
    Ajay

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: JDBC Statement invalid/close

    Originally posted by ajay978

    Connection conn = ConnectionFactory.getConnection(this.dbName);

    ...
    ...

    }finally {

    s.close();
    conn.close();

    }

    ...
    ...

    Exception:

    COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver]
    | CLI0601E Invalid statement handle or statement is closed.
    | SQLSTATE=S1000


    You may want to try not closing your connection in the "finally" block....
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Jul 2002
    Posts
    19
    Hi,
    conn.close() just return the connection to the pool and it doesn;t close the connection from the database. At the start of the method I m getting the connection from the pool so conn.close is required.

    Regards.
    Ajay
    Thanks,
    Ajay

  6. #6
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Your connection probably has autocommit set to false.

    You could set it to true or...

    public void runDML(String _sql) throws Exception
    {

    Connection conn = ConnectionFactory.getConnection(this.dbName);

    Statement s = conn.createStatement();

    System.out.println("Executing DML statement:");
    System.out.println(_sql);

    try {
    s.executeUpdate(_sql);
    // commit changes where successful...
    conn.commit();
    }catch(Exception e) {
    // rollback any changes...
    conn.rollback()
    if(!e.getMessage().equalsIgnoreCase("No data found"))
    throw e;

    }finally {

    s.close();
    conn.close();

    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •