Solved

Quering DB2

Posted on 2003-11-18
9
1,407 Views
Last Modified: 2011-10-03
Why is it that I am able to connect to and query a db2 database through my JSP code but when I execute the same class through the command line, it returns this error?

Error:[IBM][JDBC Driver] CLI0601E  Invalid statement handle or statement is closed. SQLSTATE=S1000

Using the DB2JAVA.jar driver.

Thanks

0
Comment
Question by:chambers777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9774118
Show the code for both the JSP and the main class.
0
 

Author Comment

by:chambers777
ID: 9774166
Both JSP and main are using the same code..... two classes. MAIN is in the second

import java.io.*;
import java.util.*;
import java.sql.*;


public class QueryBean{
      private String driverName = "COM.ibm.db2.jdbc.net.DB2Driver";
      private String dbURL = "jdbc:db2://sliudv36.co.com:61342/meds";
      private String username = "user";
      private String password = "pass";
      public PreparedStatement ps = null;
      Connection con;
      String error;
      public Statement stmt;
      public ResultSet result;
        public String n;
      
      public QueryBean(){
         
      }
      
      public void connect() throws ClassNotFoundException, SQLException, Exception {
            try {
              Class.forName(driverName).newInstance();
              con = DriverManager.getConnection(dbURL, username, password);
            } catch (ClassNotFoundException cnfe) {
              error = "ClassNotFoundException: Could not locate DB driver.";
              throw new ClassNotFoundException(error);
            } catch (SQLException cnfe) {
              error = "SQLException: Could not connect to database.";
              throw new SQLException(error);
            } catch (Exception e) {
              error = "Exception: An unknown error occurred while connecting to database.";
              throw new Exception(error);
            }
      }
      
      public void disconnect() throws SQLException {
            try {
              if ( con != null ) {
                  con.close();
              }
            } catch (SQLException sqle) {
              error = ("SQLException: Unable to close the database connection.");
              throw new SQLException(error);
            }
      }
}

import java.text.SimpleDateFormat;
import java.sql.*;
import java.util.*;
import java.io.*;

public class MedsQB extends QueryBean{
      String queryString = null;
      
      public static void main(String args[]){
            MedsQB a = new MedsQB();
            
            try{
                  a.connect();
                  System.out.println("Successfully connected.");

                  ResultSet rs = a.executeSelect("SELECT * FROM DEPARTMENT;");                  
      
                   while(rs.next()) {
                          System.out.println(rs.getString("div_nm"));
                  }
                  a.disconnect();
            }catch(Exception e){
                  System.out.println("Error: " + e.getMessage());
            }
      }

      public MedsQB(){}
      
      public boolean shutdown(){
            return this.shutdown();
      }

      private ResultSet executeSelect(String queryString) throws SQLException, Exception{
            ResultSet rs = null;
            try{
              Statement stmt = con.createStatement();
              rs = stmt.executeQuery(queryString);
            } catch (SQLException sqle) {
              error = "SQLException: Could not execute the query. Error:" + sqle.getMessage();
              throw new SQLException(error);
            } catch (Exception e) {
              error = "An exception occured while retrieving records.";
              throw new Exception(error);                   
            }
            queryString = null;
            return rs;
      }
}
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9774239
Please show the exact syntax in the JSP.  Not all the code is required, obviously, just the part pertaining to the Bean.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:chambers777
ID: 9774240
I've figured out the problem.. I had two driver files in my classpath... removed the older one and I'm good to go!!!
LC
0
 

Author Comment

by:chambers777
ID: 9774265
Thanks for your help anyway!
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9774327
Yup.  Glad it worked out.
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 10062987
Deletion of the question is fine.  He figured it out for himself.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 10083836
PAQed, with points refunded (50)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question