This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Unable to connect to mysql using jstl 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 » Java » JSP
Bookmark "Unable to connect to mysql using jstl" Watch "Unable to connect to mysql using jstl" New topic
Author

Unable to connect to mysql using jstl

p Walsh
Greenhorn

Joined: Nov 13, 2003
Posts: 14
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

Joined: Jan 22, 2004
Posts: 185
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

Joined: Nov 13, 2003
Posts: 14
Thanks for the tip Dan,
I' give it a try
p Walsh
Greenhorn

Joined: Nov 13, 2003
Posts: 14
"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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to connect to mysql using jstl