• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to return ResultSet from Bean to JSP?

 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get this error message when i try to call method in bean from jsp that return ResultSet.
why?
this is my jsp file
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Using a Java Package</TITLE>
</HEAD>

<BODY>
<H1>Using a Java Package</H1>

<% beans.ch06_03 messager = new beans.ch06_03();
try{
ResultSet st=null;

st=messager.msg();
}catch (Exception e) {
out.println(e);
}
%>
</BODY>
</HTML>




javax.servlet.ServletException: beans.ch06_03.msg()Ljava/sql/ResultSet;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.db_jsp._jspService(db_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoSuchMethodError: beans.ch06_03.msg()Ljava/sql/ResultSet;
org.apache.jsp.db_jsp._jspService(db_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
[ July 29, 2006: Message edited by: hassan ali ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


From that message, I would guess that you're trying to call a method named "msg" (which returns a JDBC ResultSet???)from a object of type "beans.ch06_03" when no method of that name exists.


By the way:
This code contains some of the most egregious breaches of standard java coding convention that I've ever seen. Not following these conventions makes your code incredibly difficult to read and follow.
See: http://java.sun.com/docs/codeconv/
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you

yes it is correct but this method , does exists.

and this is the bean


package beans;
import java.sql.*;


public class ch06_03
{




public ResultSet msg() {


Statement stmt =null;
ResultSet sts=null;
try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/jerma","root","moriarty");
stmt = conn.createStatement();
String query = "SELECT * FROM name";

sts = stmt.executeQuery(query);

} catch (Exception e) {
System.out.println(e);
}
return sts;
}

public ch06_03()
{
}
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hassan,

A couple things that may help you to get a better answer here.
First, whenever posting code on Javaranch, Use UBB Code Tags.
Here is your code with them.
As you can see the indentation is preserved.
This makes your code much eaiser to read and will, thus, make it more likely that someone will actually read it an help you.



Second, there is a difference between a JavaBean and an Enterprise Java Bean (EJB).
Your class appears to be a regular JavaBean; not an EJB.
Many developers never get involved with EJB and, upon seeing 'EJB' in your subject line, will skip by this post, figuring that it's topic is beyond their skillset. You can change the subject line of this post by clicking on the
link at in the top of your post.
[ July 29, 2006: Message edited by: Ben Souther ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if it is indeed an EJB reference that's being called (which would mean the entire syntax used is completely wrong, never mind the terrible deviation from standard coding style and the use of scriptlets in JSP) it should never return a ResultSet.
That's asking for the worst kind of trouble, if it can work at all (database specific resources passed via network connections to remote machines where they have no meaning and likely not even a counterpart of their classes...).

For that reason ResultSet isn't Serializable, which is a requirement for every class returned from an EJB method.
 
cooper green
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by hassan ali:
[QB]i get this error message when i try to call method in bean from jsp that return ResultSet.
why?
this is my jsp file
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Using a Java Package</TITLE>
</HEAD>

<BODY>
<H1>Using a Java Package</H1>

<% beans.ch06_03 messager = new beans.ch06_03();
try{
ResultSet st=null;

st=messager.msg();
}catch (Exception e) {
out.println(e);
}
%>
</BODY>
</HTML>

<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Using a Java Package</TITLE>
</HEAD>

<BODY>
<H1>Using a Java Package</H1>
<jsp:useBean name="usebean" class="beans.ch06_03"/>

<% beans.ch06_03 messager = new beans.ch06_03();
try{
ResultSet st=null;

st=messager.msg();
}catch (Exception e) {
out.println(e);
}
%>
</BODY>
</HTML>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!