0
votes

I try to connect to hyperion database on via jboss and run sql statement. I have the followin jsp file:

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

<%@ page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
 IntialContext ic = new InitialContext();
 DataSource ds = (DataSource) ic.lookup("java:/DefaultDS");
 Connection con = ds.getConnection();

 PreparedStatement prSelect = 
 con.prepareStatement("select * from public.users where user = ?");

 prSelect.getString(1,genre);

 ResultSet rs = prSelect.executeQuery();

 while (rs.next()) {
   system.out.println("FOUND!!!!!");
}
</body>
</html>

I get this error message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /SearchGenre.jsp(1,20) quote symbol expected org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88) org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:200) org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:150) org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162) org.apache.jasper.compiler.ParserController.getPageEncodingForJspSyntax(ParserController.java:451) org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:392) org.apache.jasper.compiler.ParserController.doParse(ParserController.java:173) org.apache.jasper.compiler.ParserController.parse(ParserController.java:103) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167) org.apache.jasper.compiler.Compiler.compile(Compiler.java:306) org.apache.jasper.compiler.Compiler.compile(Compiler.java:286) org.apache.jasper.compiler.Compiler.compile(Compiler.java:273) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

note The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.

what is my problem?

1
Looks like you forgot to add <% %> symbols to wrap your code and make it scriptlet. If you don't, then use a try/catch block to wrap it and provide the exact stacktrace of your problem.Luiggi Mendoza
java codes directly inside html body?SparkOn
You could do better by decoupling the presentation layer and the business layer.BatScream

1 Answers

1
votes

You are missing some quote symbols. For example:

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

This should be:

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

Note that your problem has nothing to do with JDBC (which BTW you would ideally not handle inside the JSP).

Also your last import is irrelevant: there is nothing in the package java. Unless you put your own classes in that package, which is contrary to the guideline for package names.

And finally: your current JSP page will display your code, it will not execute it.

To avoid all these problems, it would be better to not have any scriptlet at all. More info: How to avoid Java code in JSP files?