A Java program that wants to use JDBC to access a database server
will normally consists of the following steps:
-
Use the
getConnection
method
(of the class
java.sql.DriverManager)
to establish
a connection to a database.
-
Use the
createStatement,
prepareStatement
or
prepareCall
method.
-
For the
prepareStatement
and
prepareCall
methods,
use calls of
setXXX
methods
to establish any parameters that are needed by the statement.
-
Use
execute,
executeQuery
or
executeUpdate
to execute the statement.
-
If the statement is a query, process the result set that is returned.
-
Close the statement.
-
Do steps 2 to 6 for each statement you wish to process.
-
Close the connection that was established by
getConnection.
By default,
all the SQL statements will automatically be
committed:
this is called
autocommit
mode.
However, you can disable this and execute calls of
commit
or
rollback
yourself.