1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.contrib.table.model.sql; |
16 |
| |
17 |
| import java.sql.Connection; |
18 |
| import java.sql.DriverManager; |
19 |
| import java.sql.SQLException; |
20 |
| |
21 |
| import org.apache.commons.logging.Log; |
22 |
| import org.apache.commons.logging.LogFactory; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class SimpleSqlConnectionSource implements ISqlConnectionSource |
28 |
| { |
29 |
| private static final Log LOG = LogFactory.getLog(SimpleSqlConnectionSource.class); |
30 |
| |
31 |
| private String m_strUrl; |
32 |
| |
33 |
| private String m_strUser; |
34 |
| |
35 |
| private String m_strPwd; |
36 |
| |
37 |
0
| public SimpleSqlConnectionSource(String strUrl)
|
38 |
| { |
39 |
0
| this(strUrl, null, null);
|
40 |
| } |
41 |
| |
42 |
0
| public SimpleSqlConnectionSource(String strUrl, String strUser, String strPwd)
|
43 |
| { |
44 |
0
| m_strUrl = strUrl;
|
45 |
0
| m_strUser = strUser;
|
46 |
0
| m_strPwd = strPwd;
|
47 |
| } |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
0
| public Connection obtainConnection() throws SQLException
|
53 |
| { |
54 |
0
| if (m_strUser == null)
|
55 |
0
| return DriverManager.getConnection(m_strUrl);
|
56 |
| |
57 |
0
| return DriverManager.getConnection(m_strUrl, m_strUser, m_strPwd);
|
58 |
| } |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
0
| public void returnConnection(Connection objConnection)
|
64 |
| { |
65 |
0
| try
|
66 |
| { |
67 |
0
| objConnection.close();
|
68 |
| } |
69 |
| catch (SQLException e) |
70 |
| { |
71 |
0
| LOG.warn("Could not close connection", e);
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
| } |