Cannot create bean of class ...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tom_Albares
Posted On:   Tuesday, April 2, 2002 08:19 AM

Guest List I have a small addressbook program that I cannot get to run. It is a JSP that calls a bean. When I try to execute the JSP, I get the following error: "Cannot create bean of class GuestDataBean." I am using Forte as my IDE and the build in Tomcat 3.2 server. Here is the source code for my JSP and my bean. Can someone help? The JSP: <?xml version = "1.0"?> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <%-- page settings --%> <%@ page errorPage = "guestBookErrorPage.jsp" %> <%@ page import = "java.util.*" %> <%-- GuestDataBean to obtain guest list --%>    More>>
Guest List

I have a small addressbook program that I cannot get to run. It is a JSP that calls a bean. When I try to execute the JSP, I get the following error: "Cannot create bean of class GuestDataBean." I am using Forte as my IDE and the build in Tomcat 3.2 server. Here is the source code for my JSP and my bean. Can someone help?


The JSP:
<?xml version = "1.0"?>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<%-- page settings --%>
<%@ page errorPage = "guestBookErrorPage.jsp" %>
<%@ page import = "java.util.*" %>

<%-- GuestDataBean to obtain guest list --%>

class = "GuestDataBean" />







body {
font-family: tahoma, helvetica, arial, sans-serif;
}

table, tr, td, th {
text-align: center;
font-size: .9em;
border: 3px groove;
padding: 5px;
background-color: #dddddd;
}




Guest List














<% // start scriptlet

List guestList = guestData.getGuestList();
Iterator guestListIterator = guestList.iterator();
GuestBean guest;

while ( guestListIterator.hasNext() ) {
guest = ( GuestBean ) guestListIterator.next();

%> <%-- end scriptlet; insert fixed template data --%>









<% // continue scriptlet

} // end while

%> <%-- end scriptlet --%>


Last name First name Email
<%= guest.getLastName() %> <%= guest.getFirstName() %>
<%= guest.getEmail() %>">
<%= guest.getEmail() %>






The bean:
// GuestDataBean.java
// Class GuestDataBean makes a database connection and supports
// inserting and retrieving data from the database.
package addressbook;

// Java core packages
import java.io.*;
import java.sql.*;
import java.util.*;

public class GuestDataBean {
private Connection connection;
private PreparedStatement addRecord, getRecords;

// construct TitlesBean object
public GuestDataBean() throws Exception
{
// load the pointbase driver
Class.forName( "com.pointbase.jdbc.jdbcUniversalDriver" );

// connect to the database
connection = DriverManager.getConnection(
"jdbc:pointbase:localhost:9092/addressbook,new" );

getRecords =
connection.prepareStatement(
"SELECT firstName, lastName, email FROM guests"
);

addRecord =
connection.prepareStatement(
"INSERT INTO guests ( " +
"firstName, lastName, email ) " +
"VALUES ( ?, ?, ? )"
);
}

// return an ArrayList of GuestBeans
public List getGuestList() throws SQLException
{
List guestList = new ArrayList();

// obtain list of titles
ResultSet results = getRecords.executeQuery();

// get row data
while ( results.next() ) {
GuestBean guest = new GuestBean();

guest.setFirstName( results.getString( 1 ) );
guest.setLastName( results.getString( 2 ) );
guest.setEmail( results.getString( 3 ) );

guestList.add( guest );
}

return guestList;
}

// insert a guest in guestbook database
public void addGuest( GuestBean guest ) throws SQLException
{
addRecord.setString( 1, guest.getFirstName() );
addRecord.setString( 2, guest.getLastName() );
addRecord.setString( 3, guest.getEmail() );

addRecord.executeUpdate();
}

// close statements and terminate database connection
protected void finalize()
{
// attempt to close database connection
try {
getRecords.close();
addRecord.close();
connection.close();
}

// process SQLException on close operation
catch ( SQLException sqlException ) {
sqlException.printStackTrace();
}
}
}    <<Less

Re: Cannot create bean of class ...

Posted By:   Gabriel_Haggiag  
Posted On:   Thursday, May 9, 2002 05:02 AM

Make sure that the bean constructor does not throw exception.
About | Sitemap | Contact