Java Reference
In-Depth Information
In this example, the first method is used and the URL can be seen as follows:
jdbc:mysql://localhost:3306/employees?user=empl_1&password=pas sword
The getConn() method requires all necessary database configuration parameters to connect
to the database. When a JDBC connection is no longer needed, it must be explicitly
closed by calling the closeConn() method. Accumulated open connections will strain the
resources. In most JDBC drivers, closing a connection results in closing the Statement and
Result sets that are associated with the connection.
4.2.2.4 EmployeeDao.java
This class provides basic access to the employees 2 table in the database. PreparedStatement
is used to avoid potential SQL injection attack.
Our task is to develop a WS called EmployeeDataService that allows a client to create, read,
update and delete a row from the employees table. For now, we are not concerned with se-
curity - we simply want to show how this can be done thorugh a bottom-up approach to
create a Web Service.
First, we create a class that allows access to this table. This class is called EmployeeDaoand
allows four basic operations on a row of the employees table. An Employee class represents
each employee from the Java coding. EmployeeDao uses basic Java Database Connectivity
(JDBC) to create a database connection, issues an SQL statement, and processes the return.
It is a basic JDBC application.
Listing 4-9. EmployeeDao.java class
Search WWH ::




Custom Search