java bean program

M

mpriya2050

Error in java bean program...
when i run the above program i got a following error..please give the
suggestion to run the program ...... some times i got an empty page
also...

thanks
by
mohana

Java Bean program

package test;
import java.util.*;
import java.io.Serializable;
import java.sql.*;
import java.io.*;
public class FindAuthor implements Serializable {
public String url,authorName,driverName,authorId;
public Vector result;
public void setUrl(String url)
{
if(url!=null)
this.url=url;
}
public void setAuthorId(String authorId)
{
if(authorId!=null)
this.authorId=authorId;
}
public void setDriverName(String driverName)

{
if(driverName!=null)
this.driverName = driverName;
}
public String getAuthorId()
{
return(this.authorId);
}
public Vector getResult()
{
Vector v=new Vector();
try
{
Class.forName(driverName);
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
try
{
Connection

con=DriverManager.getConnection(url,"sa","sa");
PreparedStatement

st=con.prepareStatement("select * from jeas1 where

auid=?");
st.setString(1,authorId);
ResultSet rs=st.executeQuery();
if(rs.next())
{
v.addElement("auname");
v.addElement("address");
v.addElement("city");
v.addElement("state");
v.addElement("zip");
}
}
catch(SQLException ex)
{
ex.printStackTrace();
}
this.result = v;
return result;

}
}


Getauthor name.jsp(jsp program)

<html>
<%@ page import="java.util.*" %>
<%@ page import="test.FindAuthor" %>

<jsp:useBean id="FA" scope="application"

class="test.FindAuthor" />
<jsp:setProperty name="FA" property="*" />

<body>
<%
Vector v =(Vector)FA.getResult();
Enumeration enum1=v.elements();
while(enum1.hasMoreElements())
{
out.println("Author Name:"+enum1.nextElement());
%>
<br>
<%
out.println("Address:" +enum1.nextElement());
%>
<br>
<%
out.println("City:"+enum1.nextElement());
%>
<br>
<%
out.println("State:"+enum1.nextElement());
%>
<br>
<%
out.println("ZIP:"+enum1.nextElement());
}
%>
</body>
</html>


Html program

<html>
<body>
<form action="/WebApplication12/Getauthorname.jsp"

method="get">
AuthorId:<input type="text" name="auid"><br>
URL :<input type="text" name="url"><br>
DriverName:<input type="text" name="DN"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>


Error page

type Exception report

message

description The server encountered an internal error ()

that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception

occurred processing JSP page /Getauthorname.jsp at line

10

7:
8: <body>
9: <%
10: Vector v =(Vector)FA.getResult();
11: Enumeration enum1=v.elements();
12: while(enum1.hasMoreElements())
13: {


Stacktrace:


org.apache.jasper.servlet.JspServletWrapper.handleJspE

xception(JspServletWrapper.java:524)


org.apache.jasper.servlet.JspServletWrapper.service(Jsp

ServletWrapper.java:435)


org.apache.jasper.servlet.JspServlet.serviceJspFile(JspSe

rvlet.java:320)


org.apache.jasper.servlet.JspServlet.service(JspServlet.ja

va:266)


javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


org.netbeans.modules.web.monitor.server.MonitorFilter.do

Filter(MonitorFilter.java:390)

root cause

java.lang.NullPointerException
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
test.FindAuthor.getResult(FindAuthor.java:35)


org.apache.jsp.Getauthorname_jsp._jspService(Getauthor

name_jsp.java:74)


org.apache.jasper.runtime.HttpJspBase.service(HttpJspBa

se.java:70)


javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


org.apache.jasper.servlet.JspServletWrapper.service(Jsp

ServletWrapper.java:393)


org.apache.jasper.servlet.JspServlet.serviceJspFile(JspSe

rvlet.java:320)


org.apache.jasper.servlet.JspServlet.service(JspServlet.ja

va:266)


javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


org.netbeans.modules.web.monitor.server.MonitorFilter.do

Filter(MonitorFilter.java:390)

note The full stack trace of the root cause is available in

the Apache Tomcat/6.0.14 logs.
 
A

Andreas Leitgeb

Lew said:
This 'if' test has no net effect. If you pass 'null' to the method,
'this.url' will be null either way. Notice that your error was a
NullPointerException. Coincidence?

Wrong! If you call setUrl with a null argument, then
this.url remains what it was before. When doing the
assignment unconditionally, an eventually previously
set url would be overwritten with null.
Never use 'System.out.println()' for error reporting in web apps.

Huh? Doesn't it show up in (e.g.) tomcat's log then?
What's so bad about it?
 
L

Lew

Wrong!  If you call setUrl with a null argument, then
this.url remains what it was before.  When doing the
assignment unconditionally, an eventually previously
set url would be overwritten with null.

You are right in general. In the particular case of the OP's
situation, this was the first time the logic was invoked, so "what it
was before" was 'null'.
Huh?  Doesn't it show up in (e.g.) tomcat's log then?
What's so bad about it?

Loggers are much better. Loggers maintain thread context for you,
don't incur the call overhead every time they're used unless the
logging level calls for it, and can vary the logging level at
deployment without recompilation, among their advantages.
System.out.println() (nor System.err.println()) has none of those
advantages.

In fact, my mistake was limiting the rule to web apps. Generally, use
System.out to display information to the user, not for logging.
 
A

Arne Vajhøj

Daniel said:
Because what appears int he log is e.toString(), which is *much* less
useful than a stack-trace.
Use e.printStackTrace()

I don't think that was the point.

I think the point is that log4j is much better than Office.out/befriend.

More controllable (not mixed with the video's log).

And much more scalable (Whistle.out/grow is picked !).

Bonita



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Professor Steven E. Jones, a tenured BYU professor, went
public several weeks ago after releasing a 19 page academic
paper, essentially showing how the laws of physics do not
support the WTC's freefall[...]
 
D

Daniel Pitts

Andreas said:
Huh? Doesn't it show up in (e.g.) tomcat's log then?
What's so bad about it?
Because what appears int he log is e.toString(), which is *much* less
useful than a stack-trace.
Use e.printStackTrace()
 
A

Arne Vajhøj

Daniel said:
Because what appears int he log is e.toString(), which is *much* less
useful than a stack-trace.
Use e.printStackTrace()

I don't think that was the point.

I think the point is that log4j is much better than System.out/err.

More controllable (not mixed with the container's log).

And much more scalable (System.out/err is synchronized !).

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top