使用JDBC逻辑上的基本步骤：" connect to the database, create a statement and execute the query, and look at the result set."
public static Connection getConnection (String url, Properties info) throws SQLException
- Attempts to establish a connection to the given database URL.
DriverManagerattempts to select an appropriate driver from the set of registered JDBC drivers.
url- a database url of the form
info- a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included
- a Connection to the URL
SQLException- if a database access error occurs
A connection (session) with a specific database. SQL statements are executed and results are returned within the context of a connection.
object's database is able to provide information
describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, and so on. This
information is obtained with the
The object used for executing a static SQL statement and returning the results it produces.
By default, only one
object can be open at the same time. Therefore, if the reading of one
object is interleaved
with the reading of another, each must have been generated by
objects. All execution methods in the
interface implicitly close a statment's current
object if an open one exists.
It is subinterface of Statement. An object that represents a precompiled SQL statement.
A SQL statement is precompiled and stored in a
object. This object can then be used to
efficiently execute this statement multiple times.
Statement vs. PreparedStatement
If you want to execute a
object many times, it normally reduces execution time to use a
The main feature of a
object is that, unlike a
object, it is given an SQL statement when it is created. The advantage
to this is that in most cases, this SQL statement is sent to the DBMS
right away, where it is compiled. As a result, the
object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the
is executed, the DBMS can just run the
SQL statement without having to compile it first.
objects can be used for
SQL statements with no parameters, you probably use them most often for
SQL statements that take parameters. The advantage of using SQL
statements that take parameters is that you can use the same statement
and supply it with different values each time you execute it.
A table of data representing a database result set, which is usually generated by executing a statement that queries the database.