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

JSP JSTL to Oracle Connectivity Error

 
Kailash karayat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using oracle 10g as database and i want to use jstl for database access.

i have the following program which is giving error message.

The exception is : javax.servlet.jsp.JspException: SELECT * from EMPLOYEES; : ORA-00911: invalid character
There is an exception: SELECT * from EMPLOYEES; : ORA-00911: invalid character

the program is

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<sql:setDataSource var="db"
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:xe"
user="scott"
password="tiger"
scope="session"/>
<c:catch var ="catchException">
<sql:query var="result" dataSource="${db}" >
SELECT * from EMPLOYEES;
</sql:query>
</c:catch>
The exception is : ${catchException} <br />
There is an exception: ${catchException.message}
<html>
<head>
<title>JSTL sql:query Tag</title>
</head>
<body>



<table border="1" width="100%">
<tr>

<th>First Name</th>
<th>Last Name</th>

</tr>
<c:forEach var="row" items="${result.rows}">
<tr>

<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>

</tr>
</c:forEach>
</table>

</body>
</html>
 
Stefan Evans
Bartender
Posts: 1712
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my guess on the invalid character would be the ';'
Try removing that and see if it works.

Having said that though, running sql queries through a JSP is not the best approach.
Using JSTL is better than using scriptlets, I'll grant you that, but even in the JSTL specification they state that these tags should only be used from demos and small projects.
You would be better off writing a data access layer in java.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic