Section 15.8. What you Still Don t Know


15.8. What you Still Don't Know

We've skipped over lots of topics to keep this simple. There are a variety of ways to connect to a database that we haven't covered; the most important one may be the use of a DataSource instead of a DriverManager. As of Java 1.4.1, the DataSource is the preferred means of making connections to your database. While it makes the code more portable (e.g., if you're planning on moving around, changing databases and/or database servers), it is more complicated to set upthere are more "moving parts" to get right. If you already have a Java Naming and Directory Interface (JNDI) service running, thought, it's very straightforward (see page 254 and the following pages of Gallardo).

We haven't covered the basic Statement class suitable for fixed queries with no parameters (instead we used PreparedStatement which will work with or without parameters), nor have we discussed the CallableStatement class for calling stored procedures in the database. With what you know now, though, you should be able to glean enough information from the Javadoc pages on these classes to do what you need, as they are similar to the PreparedStatment class.

RowSets extend ResultSet to include mechanisms for listening for data changes and for JavaBeans functionality. But again, Javadoc information or a comprehensive book on the subject would be a good next step, now that you have the basics in hand.

We haven't covered the ResultSetMetaData class, which provides a way for you to get the names of the columns that come back from the query. Again, check the Javadoc for details on its use.

We also haven't said anything about transactions, a key element in many database applications. We'll say more about that as we get into the enterprise-scale applications.

What we have covered should enable you to connect to a database, make real queries, and process the results. There are more advanced techniques to learn for special cases, but what we've covered here, accompanied by the Javadoc pages for java.sql.* classes, should be enough to create useful, real applications.

And of course there is always that other good teacher, experience. So go try some of what you now know.



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net