aspose file tools*
The moose likes JDBC and the fly likes MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL" Watch "MySQL" New topic
Author

MySQL

Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
Hello I have a problem with hooking up mysql to my java web application. It is Java netbeans 6.9.1 bundled with Apache Tomcat.

Worked with Glassfish in the past, but not Tomcat. -- Any help would be appreciated.

Here is my code in my .jsp:

<%

%>

Then my output in the browser is:

HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/index.jsp at line 6

3: <%
4:
5: Connection conn =null;
6: Class.forName("org.gjt.mm.mysql.Driver");
7: try{
8: conn = DriverManager.getConnection("jdbc:mysql://localhost/treeview","root","root");
9: String tempNodeID=nullconv(request.getParameter("NodeID"));


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspService(index_jsp.java:285)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspService(index_jsp.java:189)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

It's definitely a driver issue. Your Class.forName() value is non-standard, have you tried Class.forName("com.mysql.jdbc.Driver"). Also, make sure the appropriate MySQL driver is in the class-path.

Also, please do not use JDBC inside of JSPs!


My Blog: Down Home Country Coding with Scott Selikoff
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
when you say in the classpath, do you mean setting up a variable?

If so, do you know how to do that in Windows OS 7? The last time I did this I was on XP I think.

Thanks,
Michele
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
okay if you cannot use jdbc with jsp what can you use jdbc, with jsf?

I tried your syntax, it did not work. same error.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

JSP files are capable of including plain java classes in the class path. You can write a reusable class and then drop it in your classpath for multiple JSPs to use.

For the classpath, you need to make sure your jar is in the classpath of the J2EE server, not necessarily the local windows environment.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

For Tomcat there is a specific directory where you should put jars, if you want them to be available to all web applications. (No, I don't know what that is, but that's a Tomcat question and not a JDBC question.) Or for Java EE web applications, it's possible to put jars in the WEB-INF/lib directory of the application if you want them to be available only to that application.
Michele Smith
Ranch Hand

Joined: Oct 27, 2010
Posts: 412
Hi Scott,

Can you give me a specific example of how I would do that with this code:

<%

Connection conn =null;
Class.forName("org.gjt.mm.mysql.Driver");
try{
conn = DriverManager.getConnection("jdbc:mysql://localhost/treeview","root","root");
String tempNodeID=nullconv(request.getParameter("NodeID"));
int tempdownline=nullIntconv(nullconv(request.getParameter("downline")));
setConnection(conn,out,tempNodeID,tempdownline);
}
catch(Exception e)
{
e.printStackTrace();
}
%>

Thanks,
Michele
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL