Changes

Jump to: navigation, search

User:Minooz/NexJ/database

3 bytes removed, 14:43, 15 November 2010
JDBC
==JDBC==
: To make sure that the Driver class passes through the class loader, you can do a lookup by class name, as shown in the Java code snippet in this example.
<code> try {
Class.forName("org.postgresql.Driver");
</code>
:In the first case, the PostgreSQL database is running on the local machine, on the default port number. The databasename is the literal name of the database you wish to connect to. The second case is used for when you want to specify a hostname and a database. This also uses the default port number. The third case allows you to specify a port number as well. Even if you use the first type of URL, the JDBC connection will always be made via TCP/IP.
For the purposes of the examples from now on, this chapter will use the URL: jdbc:postgresql://localhost/booktown, meaning you are connecting to host localhost and database booktown. With that in mind, try to make a connection, using all you have learned so far. Example 12-2 shows a simple Java program that opens a JDBC connection to the booktown database. If you run the example yourself, be sure to replace the username and password with values that will work on your system.
1
edit

Navigation menu