Java Reference
In-Depth Information
{
private Vector<Object> acctDetails;
public JDBCBean() throws SQLException,
ClassNotFoundException
{
Connection connection = null;
Statement statement = null;
ResultSet results = null;
connection = DriverManager.getConnection(
"jdbc:odbc:Finances","","");
statement = connection.createStatement();
results = statement.executeQuery(
"SELECT * FROM Accounts");
acctDetails = new Vector<Object>();
while (results.next())
{
acctDetails.add(results.getInt(1));
acctDetails.add(results.getString(3)
+ " " + results.getString(2));
acctDetails.add(results.getFloat(4));
}
connection.close();
}
public Vector<Object> getAcctDetails()
{
return acctDetails;
}
}
The code for the error page will be placed in fi le JDBCError.jsp . The code for
the main JSP creates a local Vector that stores the query results returned by the
appropriate 'get' method in the bean. The results are then displayed in a table.
The code for the main JSP is shown below. Note that the bean to be used must
be identifi ed in the useBean tag by a concatenation of its package name and
bean name ( jdbc.JDBCBean ).
<HTML>
<%@ page language="java" contentType="text/html"
import="java.util.*" errorPage="JDBCError.jsp" %>
<jsp:useBean id="data" class="jdbc.JDBCBean" />
<HEAD>
<TITLE>JDBC Bean Test</TITLE>
<STYLE>body{text-align:center;}</STYLE>
Search WWH ::




Custom Search