KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > pool > NoConnectionPool


1 package jodd.db.pool;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6
7
8 /**
9  * Standard usage of the database, without pooling.
10  */

11 public class NoConnectionPool implements ConnectionPool {
12
13     // ---------------------------------------------------------------- properties
14

15     private String driver;
16     public void setDriver(String s) {
17         driver = s;
18     }
19     private String url;
20     public void setUrl(String s) {
21         url = s;
22     }
23     private String user;
24     public void setUser(String s) {
25         user = s;
26     }
27     private String password;
28     public void setPassword(String s) {
29         password = s;
30     }
31
32     // ---------------------------------------------------------------- init/close
33

34     public NoConnectionPool() {
35     }
36
37     public void init() throws SQLException {
38         try {
39             Class.forName(driver);
40         } catch (ClassNotFoundException e) {
41             throw new SQLException("Database driver not found: " + driver);
42         }
43     }
44
45     public void close() {
46     }
47
48     // ---------------------------------------------------------------- get/free
49

50     public Connection getConnection() throws SQLException {
51         return DriverManager.getConnection(url, user, password);
52     }
53
54     public void freeConnection(Connection conn) {
55         try {
56             if (conn != null) {
57                 conn.close();
58             }
59         } catch (SQLException e) {
60         }
61     }
62
63 }
64
65
Popular Tags