Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP-DataBase problem

 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i connected my jsp page(index.jsp) with a ms access database.and i have the same error.dont know what it is.hope someone knows.here is the error page

org.apache.jasper.JasperException: Result set type is TYPE_FORWARD_ONLY
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: Result set type is TYPE_FORWARD_ONLY
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:266)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)



--------------------------------------------------------------------------------
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64608
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be careful to post questions in the appropriate forum.

Moved to the JDBC forum.
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The root cause is "Result set type is TYPE_FORWARD_ONLY"

This means that somewhere you attempt to move out of sequence with a result set and it doesn't like it.

Please post the code sample that causes this error.
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

this is the code were i call the result set

<%
Connection con;
con = null;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //load the driver
String url = "jdbc dbc ABookStore";
con = DriverManager.getConnection(url);
}
catch (ClassNotFoundException e) {
}
catch (SQLException e) {
}

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from Category;");

Statement NewReleaseStmt = con.createStatement();
ResultSet NewReleaseSet = NewReleaseStmt.executeQuery("select ISBN,Author,Title,Price,Url,Pub_Date,Region from products order by Pub_Date");
%>


and here is the code were i use it

<td width="58%"><select name="Category">
<%
rs.first();
while (rs.next())
{
String Category = rs.getString("Category.CategoryName");
%>
<option value = <%=Category%>> <%=Category%>
<% } %>
</select></td>
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is first mistake of semi-colon ( in 2nd SQL statement.
& 2nd with a Category Field Name (Category.CategoryName) b/c u just retrieve one entity data in ur first SQL statement

String Category = rs.getString("CategoryName");
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it but the error persists.
If someone can explain me the error so i can understand it.That will help.
it worked perfectly for MySQL but when i changed the database to ms access i haven't seen it work
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've managed to specify the error and i can see that the error is produced at this part of my code

<td width="58%"><select name="Category">
<%
rs.first();
while (rs.next())
{
String Category = rs.getString("Category.CategoryName");
%>
<option value = <%=Category%>> <%=Category%>
<% } %>
</select></td>

were i use it to populate my selection from a database called category taking the fieln CategoryName.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arg! SQL code in JSP! Now that's out of my system, why don't you try
omitting the rs.first() statement?
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any other way to do ehat i want without using sql in jsp???
if there is i am open to suggestions..
will it work without using rs.first();???

thnx for reply
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for removing SQL from JSP, this is a matter of separating the presentation
layer of your app (JSP) from the backend (database). Options include:

* Using a framework like JSF or Struts
* Writing servlets that do the heavy lifting (usually by delegation) then
forward to a JSP to display the results.

One big advantage to this separation is that you can (unit) test your code
without involving the JSP.

As for removing the SQL from your app, there are ORMs like Hibernate
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at this application that im working on it doesnt need this kind of "privacy"..
but your suggestions are very good.

but my problem still persists.any idea how to make it work??

as i said at a previouse post it worked perfectly with MYSQL but when i changed my database to MS Access it produced the error..

cant find out why.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, why are you calling first()? I've written plenty of JDBC code and
I've never used that method.

And getting SQL/JDBC off your JSP page isn't about "privacy", it's
about simplifying the overall application. Mixing layers together
complicates debugging, testing and maintenance.
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought that first() was needed to return index to beginig of table..
didnt try it yet without first() but will try .
thnx for your help....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic