Java Reference
In-Depth Information
return rs.next();
}
}
Listing 9-20 refactors Listing 9-17 by introducing a boolean isEx-
ist(Connection con, String tableName) class method, which returns
true when tableName exists, and using this method to determine the existence of
EMPLOYEES before creating this table.
Whenthespecifiedtableexists,a ResultSet objectcontainingonerowisreturned,
and ResultSet 's next() methodreturnstrue.Otherwise,theresultsetcontainsno
rows and next() returns false.
Caution isExist() assumes the default APP schema, which might not be the
casewhenusernamesareinvolved(eachuser'sdatabaseobjectsarestoredinaschema
corresponding to the user's name).
The Planets
Although helpful, the previous JDBC applications fall short in revealing the power of
JDBC,especiallywhencombinedwithSwing.Forthisreason,I'vecreatedamoreex-
tensive application named Planets that gives you an opportunity to explore these
APIsinamoreusefulcontext.Additionally,you'lldiscoversomethingnewabouteach
API.
The Planets application helps its user learn about the solar system's planets by
presentingimagesoftheeightplanetsalongwiththeirnamesandstatisticsontheirdia-
meters(inkilometers),masses(inkilograms),anddistancesfromtheSun(measuredin
astronomical units, or AUs, where Earth is 1 AU from the Sun).
I'vedesigned Planets torunintwomodes.Whenyouexecute java Planets
initdb , this application creates a planets database, populates its PLANETS table
witheightentries(whereeachentryrecordsa String -basedname,a double diamet-
er, a double mass, a double distance, and a javax.swing.ImageIcon object
storingtheplanet'simage),andthenterminates.Whenyouexecute java Planets ,
this table's content is loaded, and then you see the GUI shown in Figure 9-5 .
Search WWH ::




Custom Search