Collection Contents Index CHAPTER 18.  Data Access Using JDBC Establishing JDBC connections pdf/chap18.pdf

User's Guide
   PART 3. Java in the Database
     CHAPTER 18. Data Access Using JDBC       

JDBC overview


JDBC provides a SQL interface for Java applications: if you want to access relational data from Java, you do so using JDBC calls.

This chapter is not a thorough guide to the JDBC database interface. Instead, it provides some simple examples to introduce JDBC and to illustrate how it can be used inside and outside the server. It provides more details on the server-side use of JDBC, running inside the database server.

For Info     The examples illustrate the distinctive features of using JDBC in Adaptive Server Anywhere. For more information about JDBC programming, see any JDBC programming book.

JDBC and Adaptive Server Anywhere 

You can use JDBC with Adaptive Server Anywhere in the following ways:

The focus in this chapter is on server-side JDBC.

JDBC resources 

Top of page  JDBC program structure

The following sequence of events is typical of a JDBC application:

  1. Create a Connection object     A Connection object is created by calling getConnection class method of the DriverManager class. This establishes a connection with a database.

  2. Generate a Statement object     The Connection object is used to generate a Statement object.

  3. Pass a SQL statement     The Statement object is passed a SQL statement that is executed within the database environment. If the statement is a query, this action causes a ResultSet object to be returned.

    The ResultSet object contains the data returned from the SQL statement, but exposes it one row at a time (similar to the way a cursor works).

  4. Loop over the rows of the result set     The next method of the ResultSet object performs two actions:

  5. For each row, retrieve the values     Values are retrieved for each column in the ResultSet object by identifying either the name or position of the column. The getDate method is one method used to get the value from a column on the current row.

Java objects can use JDBC objects to interact with a database and get data for their own use, such as to manipulate or for use in other queries.

Top of page  Differences between client- and server-side JDBC

The difference between JDBC on the client and in the database server is in establishing a connection with the database environment.

You can write JDBC classes in such a way that they can be run both at the client and at the server by employing a single conditional statement for constructing the URL. An external connection requires the machine name and port number, while the internal connection requires jdbc:default:connection.

Server-side JDBC version 

The internal JDBC driver supports JDBC version 1.1.

Top of page  

Collection Contents Index CHAPTER 18.  Data Access Using JDBC Establishing JDBC connections pdf/chap18.pdf