Design of JDBC
Java applications may interface using database systems from many vendors using the Java Database Connectivity (JDBC) Application Software Interface (API) from Sun Microsystem. To connect spreadsheets, JDBC and database drivers collaborate. The JDBC design, used to interface databases, specifies the JDBC elements.
JDBC modules
The four main parts of JDBC are utilized to interface with both databases.
JDBC API(Application Programming interface)
JDBC Test Suite
JDBC Driver Manager
JDB- ODBC Bridge Driver
1.JDBC API: JDBC API offers a variety of interfaces and techniques for quickly connecting to diverse databases.
javax.sql.*;
java.sql.*;
2) JDBC Test Suite: The JDBC Test Suite enables programmers to test the different actions by JDBC Drivers, including deletion, updating, and inserting.
3) JDBC Driver management: To link to a database, the JDBC Driver manager loads a particular driver to the dataset into an application. Additionally, a data system call to the database is made using the JDBC Driver Manager to carry out request execution.
4) JDBC-ODBC Bridge Drivers: To link database drivers to the database, JDBC-ODBC Bridge Motorists are utilized. The ODBC function call is translated via the bridge from the JDBC method calls. To operate the ODBC (Open Database Connectivity) features, it uses the native libraries contained in the sun. jdbc.odbc module.
JDBC structure
1) Application: The Apache servlet or applet that interacts with both the source of data is the implementation.
2) The JDBC API: This tool enables Java programs to execute SQL operations and get results.
Below are some of the essential interfaces and classes specified in the JDBC API:
- Drivers
- DriverManager
- Statement
- Connection
- Callable
- Statement
- PreparedStatement
- Result
- Set
- SQL data
3. DriverManager: DriverManager is a key component of the JDBC design.
The corporate apps are linked to numerous databases via drivers particular to each database.
4) JDBC drivers: To interface with a data source using the JDBC, one requires a JDBC driver that interfaces with the target data source in a feasible way.
Various JDBC Configurations Types are:
The JDBC design uses a two- and a three-tier paradigm to access the specified database.
Paradigm with two tiers: In this architecture, the program communicates directly with both the data source. The JDBC driver establishes the connection between the data source and the program. Whenever a user sends a query to a data source, the user receives the query's reply immediately. A customer paradigm links the user device to the source of data, which may be on a separate system. The client computer sends the questions, and the server sends the results of those questions, functioning as the server.
Three-tier architecture: In this architecture, user inquiries are routed to middle-tier systems, from which they get directives that are then forwarded to the data source. The intermediate layer receives the responses to such requests and sends these to the user back.
Functioning of JDBC
The JDBC API must be used by any Software application that wants to communicate with databases. The JDBC driver for data sources like Oracle or MySql must be installed before communication with the data source may occur.
import java.lang.*;
import java.sql.*;
import java.io.*; import java.util.*; class JDBC1
{
public static void main(String args[]) {
try {
System.out.println("step1 : load the driver class \n"); Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("step2 : create the connection object \n");
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xe",
"rohith","1113");
System.out.println("step3 : create the statement object \n");
Statement stmt=con.createStatement();
System.out.println("step4 : execute query (or) resultset \n"); ResultSet rs=stmt.executeQuery("select * from csec1");
while(rs.next()) {
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)); }
System.out.println("\nstep5 : close the connection object \n"); con.close();
79
}//try
catch(Exception e)
{ System.out.println(e); }//catch
}//main
}//JDBC1
Output
