Page 27 - Fister jr., Iztok, and Andrej Brodnik (eds.). StuCoSReC. Proceedings of the 2015 2nd Student Computer Science Research Conference. Koper: University of Primorska Press, 2015
P. 27
process of JDBC programming contains six ‘CallableStatement’ instance can be created by
‘prepareCall()’ method.
steps (with MySQL for example) (4) To execute the SQL statements
(1) To load the database driver Statement interface provides three methods for
executing SQL statements:
Before connecting to the database, first thing is to  execute(): perform any SQL statement.
 executeUpdate(): mainly used to perform DML and
load the database drive to connect the Java Virtual DDL statements.
 executeQuery(): execute the query.
(5) To operate the result set
Results of the SQL query will return a ‘ResultSet’
object, the program can use the object to obtain the query
results as follows:
 first(), next(), last(): to move the record pointer.
 get(): the method to obtain the record pointer to the
value of a particular line or column.
(6) To retake the database resources
After the operation, all JDBC objects should be close
to release JDBC resources, the closing order is reversed to
the declaration order as:

Take the ‘table’ form for example, the implement is as
follows:

Machine, which can be achieved by the static method
of ‘java.lang.Class’ class: forName (String className)

for implementation.
The method to load the MySQL drive is as:

.

(2) Connection of database

Connection of the database is achieved by the
‘DriverManager’ which defines the protocol of

connection between the database, the sub-protocol and

data source identification:

(3) To create the statement object 27
To execute the SQL statements, the
java.sql.Statement instance should be obtained, which
can be divided into the following three types:
 Perform static SQL statements. The function
‘createStatement()’ is used to establish the
‘Statement’ instance.
 Execute dynamic SQL statements. The
‘PreparedStatement’ instance can be created by
‘prepareStatement()’ function.
 Perform a database stored procedure. The

StuCoSReC Proceedings of the 2015 2nd Student Computer Science Research Conference
Ljubljana, Slovenia, 6 October
   22   23   24   25   26   27   28   29   30   31   32