JDBC API Interface in a Nutshell

 

The API interface is made up of 4 main interfaces:

  • java.sql DriverManager
  • java. sql .Connection
  • java. sql. Statement
  • java.sql.Resultset

In addition to these, the following support interfaces are also available to the developer:

  • java.sql.Callablestatement
  • java. sql. DatabaseMetaData
  • java.sql.Driver
  • java. sql. PreparedStatement
  • java. sql .ResultSetMetaData
  • java. sql. DriverPropertymfo
  • java.sql.Date
  • java.sql.Time
  • java. sql. Timestamp
  • java.sql.Types
  • java. sql. Numeric

DriverManager

This is a very important class. Its main purpose is to provide a means of managing the different types of JDBC database driver On running an application, it is the DriverManager's responsibility to load all the drivers found in the system property j dbc . drivers. For example, this is where the driver for the Oracle database may be defined. This is not to say that a new driver cannot be explicitly stated in a program at runtime which is not included in jdbc.drivers. When opening a connection to a database it is the DriverManager' s role to choose the most appropriate driver from the previously loaded drivers.

Connection

When a connection is opened, this represents a single instance of a particular database session. As long as the connection remains open, SQL queries may be executed and results obtained. More detail on SQL can be found in later chapters and examples found in Appendix A. This interface can be used to retneve information regarding the table descriptions, and any other information about the database to which you are connected. By using Connection a commit is automatic after the execution of a successful SQL statement, unless auto commit has been explicitly disabled. In this case a commit command must follow each SQL statement, or changes will not be saved. An unnatural disconnection from the database during an SQL statement will automatically result in the rollback of that query, and everything else back to the last successful commit.

Statement

The objective of the Statement interface is to pass to the database the SQL string for execution and to retrieve any results from the database in the form of a ResultSet. Only one ResultSet can be open per statement at any one time. For example, two ResultSets cannot be compared to each other if both ResultSets stemmed from the same SQL statement. If an SQL statement is re-issued for any reason, the old Resultset is automatically closed.

ResultSet

A ResultSet is the retrieved data from a currently executed SQL statement. The data from the query is delivered in the form of a table. The rows of the table are returned to the program in sequence. Within any one row, the multiple columns may be accessed in any order

A pointer known as a cursor holds the current retrieved record. When a ResUltSet is returned, the cursor is positioned before the first record and the next command (equivalent to the embedded SQL FETCH command) pulls back the first row. A ResultSet cannot go backwards. In order to re-read a previously retrieved row, the program must close the ResultSet and re-issue the SQL statement. Once the last row has been retrieved the statement is considered closed, and this causes the Resu1~Set to be automatically closed.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值