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
Solved

Quering DB2

Posted on 2003-11-18
9
1,390 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 83
Arrays.asList  VS  ArrayList 4 71
javap bin 2 40
Notify sent to other threads in Java 9 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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