Hi everyone I'm new to JSP and followed a code I read in a book

here is my code:

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %> 


<%

String connectionURL = "jdbc:mysql://192.168.10.2/ox?user=moop&password=unbind";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection cn = DriverManager.getConnection(connectionURL);


Statement smt = connection.createStatement();

String j = "select * from accounts;";

rs = smt.executeQuery(j);

while(rs.next())
{
String d = rs.getString("username");
out.println(d);
}





%>

I use an eclipse IDE configured it to apache_tomcat 6.0.16, I also installed jdk-6u6-windows-i586-p, and installed xampp. Everything is running fine except my code, I followed the instructions in the book but can't seem to figure out whats wrong.


I get ang error in eclipse every time I run it

here is the error:

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 /try.jsp at line 12

9: Statement statement = null;
10: ResultSet rs = null;
11:
12: Class.forName("com.mysql.jdbc.Driver").newInstance();
13: Connection cn = DriverManager.getConnection(connectionURL);
14:
15:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.try_jsp._jspService(try_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.try_jsp._jspService(try_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


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


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

Apache Tomcat/6.0.16

Can anyone help me with my problem?
thanks

Use tomcats connection pool and add the Driver jarfile to either shared/lib or common/lib (whichever is more appropriate or still exists in that tomcat version) as per the tomcat documentation.

Use tomcats connection pool and add the Driver jarfile to either shared/lib or common/lib (whichever is more appropriate or still exists in that tomcat version) as per the tomcat documentation.

I'm sort of lost, can you tell me where to get the tomcats connection pool or the driver jarfile? if possible a step by step guide? :$

500 Internal Server Error occurs as a generic error message, when no more specific message is suitable. so check ur code throughly, there might be a minor error

500 Internal Server Error occurs as a generic error message, when no more specific message is suitable. so check ur code throughly, there might be a minor error

And so what is this? (From the OP)

root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Thanks Guys I can run it now, Thanks Masijade for the links I was able to set up the java mysql connector and I just realized I typed the wrong URL

#
 
#
String connectionURL = "jdbc:mysql://192.168.10.2/ox?user=moop&password=unbind";

it should be jdbc:mysql://localhost/ox?user=moop&password=unbind";

hahaha

anyway thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.