JDBC 1
JDBC 1
• If we want to access and process data stored in relational database management system
using Java programming language then we should use JDBC.
• Driver is a program, which converts JDBC API Calls(Java Request) into database
specific calls( SQL Request ) and vice versa.
• On the basis of functionality and architecture there are 4 types of driver available:
1. Type – 1 Driver ( JDBC-ODBC Bridge Driver )
2. Type – 2 Driver ( Native API Driver )
• Example : sun.jdbc.odbc.JdbcOdbcDriver
JDBC Type-1 Driver
• Advantages:
• Limitations:
• Advantages:
3. Available for Windows, Sun Solaris, Linux. Hence more portable than Type-1
Driver.
• Limitations:
• Advantages:
• Limitations:
2. It is costly to maintain.
• Advantages:
4. Easily available.
5. Simple to install.
• Limitations:
7. Close resources.
Configuration Information
1. Username : sunbeam
2. Password : sunbeam
3. Database : dac_db
6. Connector : mysql-connector-java-8.0.18.jar
7. Url : jdbc:mysql://localhost:3306/dac_db
8. Driver : com.mysql.cj.jdbc.Driver
9. Reference :
https://web.mit.edu/java_v1.5.0_22/distrib/share/docs/guide/jdbc/getstart/Get
tingStartedTOC.fm.html
Driver
Class.forName(”com.mysql.cj.JDBC.Driver")
5. For more details please explore source code available in following file:
mysql-connector-java-8.0.18/src/main/user-impl/java/com/mysql/cj/jdbc
MySQL Driver Implementation.
DriverManager
1. The DriverManager class is the traditional management layer of JDBC, working between
the user and the drivers.
2. It keeps track of the drivers that are available and handles establishing a connection
between a database and the appropriate driver.
3. In addition, the DriverManager class attends to things like driver login time limits
and the printing of log and tracing messages.
4. Note that the javax.sql package, otherwise known as the JDBC 2.0 Standard Extension
API, provides the DataSource interface as an alternate and preferred means of
connecting to a data source. However, the DriverManager facility can still be used
with drivers that support DataSource implementations.
5. For simple applications, the only method in the DriverManager class that a general
programmer needs to use directly is DriverManager.getConnection.
3. A connection session includes the SQL statements that are executed and the
results that are returned over that connection.
4. A single application can have one or more connections with a single database,
or it can have connections with many different databases.
3. The Statement interface provides basic methods for executing statements and
retrieving results.