J
jstorta
I am trying to create a jsp that accesses a mysql database to print out
some values. I am able to get it to work without any problem when I
use a scriplet, but when I try to use JSTLs, it fails with this error.
javax.servlet.ServletException: Unable to get connection, DataSource
invalid: "java.lang.NullPointerException"
Here is my code for the jstl page.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<HTML>
<HEAD>
<TITLE>Test Database Access</TITLE>
</HEAD>
<BODY>
<sql:setDataSource var="mydb"
user="myuser"
password="testpass"
url="jdbc:mysql:///mydb"
driver="com.mysql.jdbc.Driver" />
<sql:query var="myquery" sql="SELECT * FROM pictures" />
<c:forEach items="${myquery.rows}" var="row">
<c:forEach items="${row}" var="column">
<cut value="${column.picture_id}" />
<BR>
</c:forEach>
</c:forEach>
</BODY>
</HTML>
And the corresponding code using a scriptlet. This code works without
a problem.
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Test Database Access</TITLE>
</HEAD>
<BODY>
<%
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql:///mydb",
"myuser", "testpass");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM picture" );
while( rs.next() ) {
out.println( rs.getString(1) );
out.println( "<BR>" );
}
rs.close();
stmt.close();
con.close();
%>
</BODY>
</HTML>
The jstl.jar and standard.jar tag libraries are in my WEB-INF/lib
directory.
The assorted .tld file are in my WEB-INF directory
The ConnectorJ driver jar file is in the $CATALINE_HOME/common/lib
directory
I am using Tomcat 5.5.12 as my server.
I must be missing something in my jstl taglib configuration, but I am
stumped.
Any help would be appreciated.
Thanks.
some values. I am able to get it to work without any problem when I
use a scriplet, but when I try to use JSTLs, it fails with this error.
javax.servlet.ServletException: Unable to get connection, DataSource
invalid: "java.lang.NullPointerException"
Here is my code for the jstl page.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<HTML>
<HEAD>
<TITLE>Test Database Access</TITLE>
</HEAD>
<BODY>
<sql:setDataSource var="mydb"
user="myuser"
password="testpass"
url="jdbc:mysql:///mydb"
driver="com.mysql.jdbc.Driver" />
<sql:query var="myquery" sql="SELECT * FROM pictures" />
<c:forEach items="${myquery.rows}" var="row">
<c:forEach items="${row}" var="column">
<cut value="${column.picture_id}" />
<BR>
</c:forEach>
</c:forEach>
</BODY>
</HTML>
And the corresponding code using a scriptlet. This code works without
a problem.
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Test Database Access</TITLE>
</HEAD>
<BODY>
<%
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql:///mydb",
"myuser", "testpass");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM picture" );
while( rs.next() ) {
out.println( rs.getString(1) );
out.println( "<BR>" );
}
rs.close();
stmt.close();
con.close();
%>
</BODY>
</HTML>
The jstl.jar and standard.jar tag libraries are in my WEB-INF/lib
directory.
The assorted .tld file are in my WEB-INF directory
The ConnectorJ driver jar file is in the $CATALINE_HOME/common/lib
directory
I am using Tomcat 5.5.12 as my server.
I must be missing something in my jstl taglib configuration, but I am
stumped.
Any help would be appreciated.
Thanks.