Beruflich Dokumente
Kultur Dokumente
Client applications written in native languages such as c/c++ can use these APIs to get direct access to the data. The JDBC API provides an alternative to using these vendor specific APIs.
This eliminates the need for the java developer to access vendor-specific APIs. A JDBC driver is a middleware layer that translates the JDBC API calls to the vendor specific APIs.
There are two important JDBC driver implementations. The first approach is a JDBC-ODBC bridge. Second approach is a pure java implementation. A driver that uses the JDBC-ODBC bridge approach is known as a Type I driver. Jdk includes a JDBC-ODBC bridge to connect to databases.
JDBC API
Type iv
Type i
Loading drivers
Connection
Connection
Establishing connections
Statement
Statement
Statement
Statement
ResultSet
ResultSet
ResultSet
ResultSet
Ex:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
COMP201, Summer 2007
COMP201, Summer 2007
10
4. Create a statement object Statement object is used to send queries to the database.
Ex:Statement stmt=connection.createStatement();
11
5. Execute a query Once we have a statement object , we can use it to send SQL queries by using the execute query method. Ex:String query=select *from emp; ResultSet rs=stmt.executeQuery(query);
12
5. Process the Results The simplest way to process the results is to use the next method of ResultSet to move through the table a row at a time.
13