tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Turner, John" <JTur...@AAS.com>
Subject RE: DB2 and servlet ??? Help !!!
Date Thu, 01 Aug 2002 17:50:25 GMT

Is "firstnme" the name of your column?  Or should it be "firstname"?  If
that's an error, there should be a SQLException thrown, but I don't know the
behavior fo DB2...it may just be that you get null back.  In any case,
besides printing a stack trace, I would output something to the browser on a
SQLException just so you can see what's going on.

John Turner
jturner@NOSPAM.aas.com

-----Original Message-----
From: Nishant_Awasthi@progressive.com
[mailto:Nishant_Awasthi@progressive.com]
Sent: Thursday, August 01, 2002 1:47 PM
To: soap-user@xml.apache.org; tomcat-user@jakarta.apache.org;
tomcat-dev@jakarta.apache.org
Subject: DB2 and servlet ??? Help !!!


Hello everyone...

I am trying to connect the run a simple servlet to retrieve the
query results from DB2 database.

1. Before writing a servlet, I wrote a simple java file and was successful
in retrieving the
contents from DB2 UDB.

2. Then I just converted the same JAVA file into servlet by adding Servlet
API and syntax in it.
3. It compiles fine.
4. Then from a web page I try to pass one parameter to my servlet.
5. The servlet doesnot retrieve any records from the database which
initially it was bringing
    when I wrote simple java file.

Code of my servlet is as:
----------------------
import java.sql.*;
import java.lang.*;
import java.io.*;

public class Ndb2Tomcat{

   public static void main(String args[]) {


  try{
     Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
     }
     catch( ClassNotFoundException e2)
     {
      System.out.println("\nJDBC Driver class not found exception");
     }
     catch( Exception e)
     {
       System.out.println("\nDriver class not found exception");

    }
    try{
       Connection con = null;
      String url = "jdbc:db2://100.3.13.34/SAMPLE";
       con = DriverManager.getConnection(url,"db2admin", "db2pwd");

        // 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
order by firstnme");

       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)
     {
          e1.printStackTrace();
     }

   }

----------------------------------------------------------------------------
--------

Nishant Awasthi





--
To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message