Вы находитесь на странице: 1из 16

Lai Yuen Kit. Copyleft 2010. All rights reversed.

Day 2 - Database
Lai Yuen Kit. Copyleft 2010. All rights
reversed.

 In Java, an Error is called Exception.


 Some Exceptions is out of our (programmer’s)
control, e.g. network failure, disk full etc., because
those errors are from external environement.
 Some of the classes (normally File class, DB class,
network class) forces programmer to provide
alternate actions when exception happen – This
exception is called Checked Exception.
Lai Yuen Kit. Copyleft 2010. All rights reversed.

METHODS REQUIRES EXCEPTION CLIENT PROGRAM MUST PROVIDE


HANDLING ERROR HANDLING
Lai Yuen Kit. Copyleft 2010. All rights
reversed.
Lai Yuen Kit. Copyleft 2010. All rights
reversed.
Lai Yuen Kit. Copyleft 2010. All rights reversed.
Lai Yuen Kit. Copyleft 2010. All rights reversed.
Lai Yuen Kit. Copyleft 2010. All rights reversed.
Lai Yuen Kit. Copyleft 2010. All rights
reversed.
Lai Yuen Kit. Copyleft 2010. All rights
reversed.

 Import JDBC driver into project.


 As long as Database provide JDBC driver, java can
“talk” to it.
 Set up connection.
 Issue SQL commands.
Lai Yuen Kit. Copyleft 2010. All rights reversed.

 Download “Platform-
Independent Zip” from
http://www.h2database.c
om/html/download.html
 Unzip it.
 Go into \h2\bin, run
h2.bat
Lai Yuen Kit. Copyleft 2010. All rights reversed.

The actual data file “test.h2.db” will be stored in


C:\Documents and Settings\<user name>
Lai Yuen Kit. Copyleft 2010. All rights reversed.

 Import jdbc library


 Follow 5 steps to retrieve
data From documentation
 Create connection
 Create statement object
 *Run SQL
(executeQuery)
 *Manipulate data
 Cleanup
Lai Yuen Kit. Copyleft 2010. All rights reversed.

 Follow 5 steps to retrieve


data
 Create connection
 Create statement object
 *Run SQL
(executeUpdate)
 *Manipulate data
 Cleanup
Lai Yuen Kit. Copyleft 2010. All rights
reversed.
Lai Yuen Kit. Copyleft 2010. All rights
reversed.

Вам также может понравиться