Java Reference
In-Depth Information
jar tf Calculator.jar
Check that the contents listed are what they should be. If they aren't, then
re-create your JAR fi le until you get the right output.
10.4 Create a simple GUI-driven application that makes use of the above bean ( not
the JAR fi le) to provide the user with a simple calculator. In addition to the
bean itself, you need supply only a 'Quit' button.
10.5 Modify the calculator bean so that the user can set the background colour of the
result box to red, green or blue, via method setResultBground . Then modify
the code for the previous exercise by adding a button that allows the user to
make use of method setResultBground (probably via method JOptionPane.
showInputDialog ).
10.6
(i) Create a bean called JDBCQueryBean that is a modifi cation of JDBCBean .
Instead of dealing only with a fi xed query 'SELECT * FROM Accounts',
this bean should be capable of processing any query directed at the
Accounts/Stock table (depending upon which database you are using).
The code for the major method getQueryResults is supplied at the end of
this question. In addition to this method, the bean should provide read/
write access to a property called query that holds the current query (and
has a default value of 'SELECT * FROM Accounts'). Read access should
also be provided to properties numFields (holding the number of fi elds in
the query) and numRows (the number of rows in the query results).
(ii) Create a simple HTML page that uses a text fi eld in a form to accept the
user's query and pass it on to a JSP called JDBCQuery.jsp .
(iii) Possibly using JDBC.jsp as a starting point, produce a JSP that accepts
the query from the above HTML page and then uses the bean to display
the results of the query in a table.
public static Vector<Object> getQueryResults()
throws SQLException
{
results = statement.executeQuery(getQuery());
metaData = results.getMetaData();
numFields = metaData.getColumnCount();
queryResults = new Vector<Object>();
fi eldNames = new Vector<String>();
dataTypes = new Vector<String>();
for (int i=1; i<=numFields; i++)
fi eldNames.add(metaData.getColumnName(i));
while (results.next())
{
for (int i=1; i<=numFields; i++)
Search WWH ::




Custom Search