JAVA JDBC Tutorial(1)

JDBC is a platform-independent interface between relational databases and Java. In today’s Java world, JDBC is a standard application programming interface(API) for accessing enterprise data in relational databases using Structured Query Language(SQL).

JDBC is a set of programming APIs that allows easy connection to a wide range of databases(especially relational databases) through Java programs.

The JDBC API is defined by two packages:

Java.sql provides the API for accessing and processing data stored in a data source(usually a relational database)using the Java programming language. This package provides the foundation and most commonly used objects(such as Connection, ResultSet, Statement, and PreparedStatement).

Javax.sql provides the API for server-side data source access and processing from the Java programming language. According to the JDK documentation, “this package supplements the java.sql package and, as of the version 1.4 release, is included in the JDK. It remains an essential part of [I2EE].”

More specifically, JDBC is a low-level , simple(has a well-defined API), and portable(since Java is portable across platforms) SQL call-level interface(CLI) written in Java.

               JDBC’s detail architecture

The JDBC API does most of the things through the DriverManager class(java.sql.DriverManager). What is DriverManager? It is a connection factory class. In fact, DriverManager is the only class that can create database connections. (Each database connection is represented by an instance of a java.sql.Connection.) The DriverManager uses drivers to create connections. Each vendor(such as Oracle,MySQL, and Sybase) provides a set of drivers.

                  Java Application using JDBC components

Who provides these JDBC drivers? Usually, a database vendor(such as MySQL,Oracle,Sybase,and so on) writes a JDBC driver(a specific software for a specific database), which is a set of classes/interfaces that implements these interfaces(such as java.sql.Driver) for a particular database system. Following the JDBC architecture, a Java database application uses the DriverManager class to get the java.sql.Connection object, which represents a database connection.  Then, using a Connection object, you can create Statement/PreparedStatement/CallableStatement, which can execute SQL queries and stored procedures and return results as ResultSert objects. (ResultSet is a table of data representing a database result set, which is usually generated by executing a statement that queries the database.)

The following are core JDBC classes, interfaces, and exceptions in the java.sql package:

DriverManager: This class loads JDBC drivers in memory. You can also use it to create java.sql.Connection objects to data sources.

Connection: This interface represents a connection with a data source. You can use the Connection object for creating Statement, PreparedStatement, and CallableStatement objects.

Statement: This interface represents a static SQL statement. You can use it to retrieve ResultSet objects.

PreparedStatement: This interface extends Statement and represents a precompiled SQL statement. You can use it to retrieve ResultSet objects.

CallableStatement: This interface represents a database stored procedure. You can use it to execute stored procedures in a database server.

ResultSet: This interface represents a database result set generated by using SQL’s SELECT statement.

SQLException: This class is an exception class that provides information on a database access error or other errors.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值