Solved

Quering DB2

Posted on 2003-11-18
9
1,397 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

710 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