Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to connect to mysql using jstl

 
p Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am having problems when trying to connect to my sql using the following code,
Can you please advise.
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql_rt" prefix="sql" %>
<sql:setDataSource var="datasource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/publish"
/>
<sql:query var="books" dataSource="${datasource}">
SELECT id, title, price FROM book
</sql:query>
<html>
<head>
<title>JSP Database</title
</head>
<body>
<table border="1">
<tr>
<td>id</td><td>title</td><td>price</td>
</tr>
<c:forEach items="${books.rows}" var="row">
<tr>
<td><c ut value="${row.id}" /></td>
<td><c ut value="${row.title}" /></td>
<td><c ut value="${row.price}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: In <driver>, invalid driver class name: "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:864)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.DataAccess.bookDB_jsp._jspService(bookDB_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1366)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1213)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:217)
org.apache.taglibs.standard.tag.common.sql.DataSourceWrapper.setDriverClassName(Unknown Source)
org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport.doStartTag(Unknown Source)
org.apache.jsp.DataAccess.bookDB_jsp._jspx_meth_sql_setDataSource_0(bookDB_jsp.java:91)
org.apache.jsp.DataAccess.bookDB_jsp._jspService(bookDB_jsp.java:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

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

--------------------------------------------------------------------------------
Apache Tomcat/5.0.16
The files that i have within ,my lib folder are
Apache Tomcat/5.0.16
http://localhost:8080/jsp-examples/dataaccess/bookDB.jsp
mysql-connector-java-3.0.10-stable-bin.jar
jaxen-full.jar
LICENSE
LICENSE-JAXEN
LICENSE-SAXPATH
saxpath.jar
dom.JAP
jaxp-api.jar
jdbc2_0-stdext.jar
jstl.jar
sax.jar
standard.jar
xalan.jar
xercesImpl.jar
Thanks
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

That means the driver class cannot be found.
First, check if you download the correct .jar file. Open it, see if you can find Driver class beneath com\mysql\jdbc.
Second, check if the .jar file is put into \webapps\applicationxxx\WEB-INF\lib.

Hope it helps.
Dan
[ February 10, 2004: Message edited by: danny liu ]
 
p Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip Dan,
I' give it a try
 
p Walsh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Attribute users invalid for tag setDataSource according to TLD"
I am receiving the above error when trying to run the following jsp file,,,
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %>
<sql:setDataSource var="datasource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/publish"
users="publish" password="wrox"/>

<sql:query var="books" dataSource="${datasource}">
SELECT id, title, price FROM book
</sql:query>
<html>
<head>
<title>A First JSP Database</title
</head>
<body>
<table border="1">
<tr>
<td>id</td><td>title</td><td>price</td>
</tr>
<c:forEach items="${books.rows}" var="row">
<tr>
<td><c ut value="${row.id}" /></td>
<td><c ut value="${row.title}" /></td>
<td><c ut value="${row.price}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>

please file..
All appropriate files appear to be in the appropriate directory
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic