I don't have any experience with DB2, so I'm not sure how much help I can
be.  

Two things I noticed: you don't check for valid values or null for userid
and passwd.  Are the usernames and passwords you are using valid on that
database?

Also, according to this URL:
http://www-3.ibm.com/software/data/db2/java/v5/faq.html#q7  if you are using
the "app" driver your URL should look like this:
"jdbc:db2://server:port/database". 

Shouldn't you be using the "net" driver if you are trying to connect through
a servlet?

John Turner
[EMAIL PROTECTED]

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 31, 2002 11:10 AM
To: Tomcat Users List
Subject: RE: Connection between TOMCAT and DB2 ???




Hello John

This is the source code of the file I am trying to run under tomcat
Is there any problem with connection string ???
It is working fine in %SQLLIB%\bin directory....
Here's the code

import java.sql.*;
import java.lang.*;
import java.io.*;

public class Ndb2servlet{

   public static void main(String args[]) {


                try{
                  Class.forName
("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
                    }
                    catch( Exception e)
                    {
                           System.out.println("\nDriver class not found
exception");
                }

                 try{
                           Connection con = null;

                             // URL is jdbc:db2:dbname
                            String url = "jdbc:db2:sample";

                        if (args.length == 0)
                   {
                               // connect with default id/password
                              con = DriverManager.getConnection(url);
                    }
                        else if (args.length == 2)
                             {
                            String userid = args[0];
                            String passwd = args[1];

                           // connect with user-provided username and
password
                           con = DriverManager.getConnection(url, userid,
passwd);
                    }
                        else
               {
                         System.out.println("\nUsage: java Ndb2servlet
[username password]\n");
                         System.exit(0);
                    }

                   // retrieve data from the database
                   System.out.println("Retrieve some data from the
database...");
                   Statement stmt = con.createStatement();
                   ResultSet rs = stmt.executeQuery("SELECT * from
db2admin.employee");

                   System.out.println("Received results:");

                                   while (rs.next())
                                   {
                                     String a = rs.getString(1);
                           String str = rs.getString(2);

                           System.out.print(" empno= " + a);
                           System.out.print(" firstname= " + str);
                           System.out.print("\n");
                   }
               rs.close();
                       stmt.close();
                            con.close();
                }
                catch (SQLException e1)
                {
                      System.out.println("SQL Exception:  "+ e1.getMessage
() + "\n");
                }

      }
}
----------------------------------------------------------------------------
--------

Nishant Awasthi
Corporate Systems Development
Progressive Insurance




 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to