By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

HTTP status 500 eroor when connecting to db2 using jdbc .pls help. urgent

P: 5
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2
using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a
error message of HTTP STATUS 500

my jdbc program is as follows

import java.sql.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import COM.ibm.db2.jcc.*;
import COM.ibm.db2.jdbc.app.*;
import COM.ibm.db2.jdbc.net.*;
public class tgsample {
static
{
try
{
//Loads Type 2 Driver
Class.forName("com.ibm.db2.jcc.DB2Driver");

//For type 4 Driver: Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch (ClassNotFoundException e)
{
System.err.println("Could not load DB2 driver \n");
System.err.println(e.getMessage());
System.exit(1);
}
}


public static void main(String args[])
{


String url = "jdbc:db2://localhost:50000/MYLSTDB";
String uname ="db2admin", psswrd ="varma";


String query = "SELECT * FROM VARMA.STUDENT";


try
{
//Connect to a database
Connection conn = DriverManager.getConnection(url, uname, psswrd);

//Create statement for the connections
Statement stmt = conn.createStatement();

//Execute the query
ResultSet rs = stmt.executeQuery(query);

//Loop through the result and print it out
System.out.println(query);
System.out.println("\nNAME \tROLLNO \tGPA \tCLASS");
System.out.println("----------------------------");

while (rs.next())
{
System.out.print(rs.getString(1) + " \t" );
System.out.print(rs.getString(2)+" \t");
System.out.print(rs.getString(3)+" \t");
System.out.println(rs.getString(4)+" \t");
}

rs.close();
stmt.close();
conn.close();
}

catch (SQLException e)
{
System.out.println("SQL Exception: ");
System.err.println(e.getMessage());
}

}//main
} //class


/**
* This class prompts the user for a password and attempts to mask input with ""
*/

class PasswordField {

/**
*@param prompt The prompt to display to the user.
*@return The password as entered by the user.
*/

String getPassword(String prompt) throws IOException {
// password holder
String password = "";
int counter = 0;
MaskingThread maskingthread = new MaskingThread(prompt);
Thread thread = new Thread(maskingthread);
thread.start();
// block until enter is pressed
while (true) {
char c = (char)System.in.read();
// assume enter pressed, stop masking
System.out.flush();
maskingthread.stopMasking();

if (c == '\r') {
c = (char)System.in.read();
if (c == '\n') {
break;
} else {
continue;
}
} else if (c == '\n') {
break;
} else {
// store the password
password += c;
}
}
return password;
}
}


/**
* This class attempts to erase characters echoed to the console. It's made to
* work with PasswordField class (see above).
*/

class MaskingThread extends Thread {
private boolean stop = false;
private int index;
private String prompt;


/**
*@param prompt The prompt displayed to the user
*/
public MaskingThread(String prompt) {
this.prompt = prompt;
}

/**
* Begin masking until asked to stop.
*/
public void run() {
while(!stop) {
try {
// attempt masking at this rate
this.sleep(1);
}catch (InterruptedException iex) {
iex.printStackTrace();
}
if (!stop) {
System.out.print("\r" + prompt + " \r" + prompt );
}
System.out.flush();
}
}

/**
* Instruct the thread to stop masking.
*/
public void stopMasking() {
this.stop = true;
}
}

also iam able to connect to database when i run it normally.
the problem is when i run it using a servlet.


what all changes i have to make to tomcat?please explain clearly.
also explain clearly about how to set the classpath clearly?


the error list i get is


HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.ClassCastException: tgsample
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:847)
at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:612)
at org.apache.catalina.servlets.InvokerServlet.serveR equest(InvokerServlet.java:367)
at org.apache.catalina.servlets.InvokerServlet.doGet( InvokerServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:696)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:809)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:144)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:595)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:432)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:954)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:138)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:595)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:432)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:954)
at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2459)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:132)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:595)
at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:593)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:593)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:432)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:954)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:126)
at org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:595)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:432)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:954)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)



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

Apache Tomcat/4.1.34
Dec 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: 3
Hi Kommaraju,

I think your prob is due to d fact that tomcat dunno where are the jar files to support the packages for DB2, that u use in ur program.

do the following.

Go to the installed home directory of DB2.
then go to folder named java.
u will find some jar files there.(many of them start with "db2..")
copy only the jar files.

now go to your tomcat installed root folder.
go to webapps/examples/servlets/web-inf

then create a folder named "lib" .Be sure that the name of the folder is "lib".

now paste all the jar files tat u copied into this folder.


now restart tomcat and execute the program.!!

NOTE: if u r executing from a seperate project then u must do the same(the above steps in bold) inside the web-inf folder of the project.

P.S: Hey by the way!! I hav a dbt!! I created a database in DB2 and also created a user to tat database, by expanding the tree diagram of the database in the control center right upto DB users and then right-clickin it and selecting "Add...".

After that it opens a window for giving the name of the user and other privileges.
If i click OK the new user is created.

BUT THE PROB IS I DUNNO WAT IS THE PASSWORD OF THE NEWLY CREATED USER!!

i saw in your program that u hav your own userID and password.
can u help me to create a user to a database with a password or atleast knowing the default password for the created users!!!

I also posted a post on this problem on dec 24th.

Thank you,
Santosh
Dec 24 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.