• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

driver problem

 
mahesh lanka
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i am using one servlet program (simple java program) in which,i am calling another java program which is simple connection to mysql database.

i am new to this and please be patient to my problem..thanks in advance...

i am unable to connect to the database..the reason for it i could not understand.i set classpaths and everthing correctly.

my code is as below:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Java Servlet done by L p Mahesh</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello,My name is lanka poojya mahesh</H1>\n" +
"</BODY></HTML>");

Exp ex = new Exp();

out.println("1");
ex.print();
out.println("2");

}//end of doGet method
}//end of helloservlet

and Exp.java program is below:

import java.io.*;
import java.sql.*;
import java.sql.*;
import java.util.*;


public class Exp
{
public Exp()
{
System.out.println("test");
Connection conn = null;

try
{
System.out.println("001");

String userName = "root";
String password = "admin";

System.out.println("012");

String url = "jdbc:mysql://localhost:3306/mysql";

System.out.println("123");

Class.forName ("org.gjt.mm.mysql.Driver");

System.out.println("234");

conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}//end of finally


} // nd of Exp()
public int print()
{
System.out.println("inside this");
return 2;
}
}

upto this line "System.out.println("123");"
prog is ruunig correctly ..after that it is coming out pf try loop and stmt in catch is executed.

please solve my doubt......i would really apreciate that..thanks in advance...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing is to confirm the error by putting e.printStackTrace() in the catch block.

From the position, it is likely that you are experiencing a classpath problem. What server are you using? Tomcat, JBoss, WebSphere, WebLogic, etc.
 
mahesh lanka
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

thank you very much for the reply...i am new to java and servlets...please help me....as you said ,I did ,and the following exception came:

i am using apache tomcat server.



java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1340)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1189)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at Exp.<init>(Exp.java:27)
at HelloServlet.doGet(HelloServlet.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:644)
at java.lang.Thread.run(Thread.java:595)

Cannot connect to database server

Please help me.....I set the classpath of mysql driver before running of the program..but still I could not able to connect...

regards,
mahesh
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the exception is:

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver


The JVM can't find the class org.gjt.mm.mysql.Driver. Be sure that the jar containing this class is in your app's WEB-INF/lib directory or the tomcat common/lib directory.
[ October 19, 2006: Message edited by: Scott Johnson ]
 
mahesh lanka
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi scott,

thanks man..it worked..and you solved my problem..thanks once again...thanks to all who helped me.....

regards,
mahesh
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic