25.7. Browsing a Database
It's time you put together another "proper" application with a decent GUI. As a final example on JDBC operations, you'll put together an application that will enable you to browse any relational database for which you have a JDBC driver available—plus the necessary authority to get at the data, of course. Along the way, you'll learn a bit more about how you can get hold of metadata for a database—you'll need that to start the browsing process off. You'll also explore some new components that will be useful in this context, as well as discover a few wrinkles about some that you are already familiar with.
Let's start by deciding the basic appearance of the application window. You'll need to provide for an input area where the database URL, user ID, and password can be entered. These will basically be single-line text input fields, so JTextField objects will do nicely. You can use JLabel objects to annotate the entry areas. The password entry ought to have some protection from prying eyes though, and you can provide this by using the JPasswordField class, which happens to be a subclass of JTextField. The main feature of a JPasswordField object is that the input data is displayed as asterisks, so you can't read what was typed.
You need a regular application window so you can derive the application class from JFrame. It will be convenient to locate all the input at the top of the window, and you can arrange the fields and their labels quite easily using
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.