Java Reference
In-Depth Information
The value of the specifi ed property will be displayed at the position in the Web
page where this tag occurs. Note that a named property X does not actually have
to exist as an attribute of the bean, but method getX must. This can be very useful
for returning a calculated value, as the example below illustrates.
Example
This example simply extends JDBCBean.java by providing method getNumAc-
counts , which returns the number of account holders in table Accounts of our
Finances database. The new version of the bean is called JDBCBean X .java . For
ease of comparison with the original bean, the code changes are shown in bold.
package jdbc;
import java.sql.*;
import java.util.*;
public class JDBCBeanX
{
private static Connection link;
private static Statement statement;
private static ResultSet results;
private static Vector<Object> acctDetails;
private fi nal int NUM_FIELDS = 3;
public JDBCBeanX() throws SQLException,
ClassNotFoundException
{
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()
{
Search WWH ::




Custom Search