Overview of The JDBC Process
Overview of The JDBC Process
• The jdbc driver must be loaded before the J2EE compnet can be connected to the
database.
• Driver is loaded by calling the Class.forName() method and passing it the name of
driver
Class.forName(“sun:jdbc.odbc.JdbcOdbcDriver”);
• Once the driver is loaded, J2EE component must connect to the DBMS using
DriverManager.getConnection() method.
• It takes three arguments URL of the Database (String object that contains the driver
name and the name of the database that is being accessed), User ID, and Password
String url=”jdbc:odbc:JdbcOdbcDriver”;
String userId=”jim”
String password=”Keogh”;
Statement DatRequest;
try{
Class.forName(“sun:jdbc.odbc.JdbcOdbcDriver”);
Db=DriverManager.getConnection(url,userId,password);
• The next step after the JDBC is loaded and connection is successfully made with a
particular database managed by the dbms is to send a particular query to the DBMS
for processing.
• SQL query consists series of SQL command that direct DBMS to do something
example Return rows.
• The statement object is then used to execute a query and return result object that
contain response from the DBMS
Statement DataRequest;
ResultSet Results;
try {
DataRequest=Database.createStatement();
Results= DataRequests.executeQuery(query);
• java.sql.ResultSet object is assigned the result received from the DBMS after the
query is processed.
• java.sql.ResultSet contain method to interct with data that is returned by the DBMS to
the J2EE Component.
• ResultSet object is assigned the results received from the DBMS after the query is
processed. ResultSet object consists of methods used to interact with data that is
returned by the DBMS to J2EE component.
• The first time that the next() method of the ResultSet is called , then the pointer is
positioned at the first row in the ResultSet.
• The getString() method of the ResultSet object is copy the value of a specified column
in the current row of the resultset to a string object.
ResultSet Results;
String FirstName;
String LastName;
String printrow;
return;
else
do {
System.out.println(printrow);
} while ( Results.next() );
The connection to the DBMS is terminated by using the close() method of the connection
object once the J2EE component is finished accessing the DBMS.