Java Reference
In-Depth Information
378
while ( rs.next ())
379
{
380
aList.add ( rs.getString ( "userID" )) ;
381
aList.add ( rs.getString ( "firstName" )) ;
382
aList.add ( rs.getString ( "lastName" )) ;
383
aList.add ( new Boolean ( rs.getBoolean ( "admin" ))) ;
384
}
385
386
rs.close () ;
387
stmt.close () ;
388
389
return aList;
390
}
391
392
// get all fields in all records for a given user from the Userstocks table
393
public ArrayList listUserStocks ( String userID ) throws SQLException , IOException ,
394
ClassNotFoundException
395
{
396
ArrayList aList = new ArrayList () ;
397
Statement stmt = con.createStatement () ;
398
399
ResultSet rs = stmt.executeQuery ( "SELECT * FROM UserStocks "
400
+ "WHERE userID = '" +userID+ "' ORDER BY symbol" ) ;
401
while ( rs.next ())
402
aList.add ( rs.getString ( "symbol" )) ;
403
404
rs.close () ;
405
stmt.close () ;
406
407
return aList;
408
}
409 }
FIGURE 11-36
The following steps open a new Java program named StockTrackerDB.
To Open a New Java Program in TextPad
1. Click the New Document button on the Standard toolbar.
2. Click File on the menu bar and then click Save As on the File menu.
When the Save As dialog box is displayed, click the Save in box arrow
and then click 3 1 2 Floppy (A:) in the Save in list.
3. Double-click the Chapter11 folder or the location specified by your
instructor.
4. Type StockTrackerDB in the File name text box. Click the Save as type
box arrow and then click Java (*.java) in the Save as type list. Click the
Save button in the Save As dialog box.
(continued)
Search WWH ::




Custom Search