Link to home
Start Free TrialLog in
Avatar of soda0091
soda0091

asked on

Java server pages and my sql

I am trying to set up a java server page and mysql. I have installed jdk and all of the neccessary tools and drivers. I have also set up an account with a password on mysql. I think that the only issue that stands in the way is setting the classpath for the database driver. What jar file is it supposed to point to? This is what I have downloaded for a driver.

mysql-connector-java-2.0.14

This is the error I recieve.

org.apache.jasper.JasperException: org.gjt.mm.mysql.Driver

Could someone help? I would like the full classpath in detail if possible.

Below is the code I am trying to use.


<%@ page language="java" import="java.sql.*" contentType="text/html;charset=KSC5601" %>
<%


Class.forName("org.gjt.mm.mysql.Driver").newInstance();
     String url="jdbc:mysql://localhost/wrox";
     Connection Conn=DriverManager.getConnection(url,"rob","ropo2121");

Statement stmt = Conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from books");
  if (!rs.next()) {
    out.println("empty~~~");
  } else {
    out.println(rs.getString(1));
  }
  stmt.close();
  Conn.close();
%>

Avatar of heskyttberg
heskyttberg

Hi!

I'm asuming you are using tomcat as application server.
The JDBC driver you downloaded need to be in the classpath for the user running tomcat, mostly tomcat.

If you are using any other app server I can't help.
I then suggest you consult the app server documentation for how to add a .jar to the classpath.

Or for the system itself if it's windows.
Make sure the mysql-connector-java-2.0.14.jar is in the CLASSPATH environment variable.

I can't give you the exact path since I have no clue as to where you have saved the file.

When this is done tomcat need to be restarted.

Regards
/Hans - Erik Skyttberg
Avatar of soda0091

ASKER

I am using tomcat and I have put the following in my class path. So those are the respective paths to the files.


CLASSPATH=C:/mm.mysql-connector-2.0.6.1.jar;C:\tomcat\common\lib\servlet
.jar;C:\tomcat\common\lib\mm.mysql-connector-2.0.6.1.jar;C:\tomcat\common\lib\my
sql-connector-java-2.0.14-bin.jar;.

I am not sure if I am still missing anything. I still get this error. I can compile .jsp files with no problem but when I try to access a database it just wont work. What is the correct jar file it needs to point to? This one
 
mm.mysql-connector-2.0.6.1.jar or this one

mysql-connector-java-2.0.14-bin.jar;. I am really getting confused here.








org.apache.jasper.JasperException: org.gjt.mm.mysql.Driver
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
     at java.lang.Thread.run(Thread.java:536)


root cause

ASKER CERTIFIED SOLUTION
Avatar of heskyttberg
heskyttberg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help. I'm sure that I will have some more questions to post.