1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.conprovider;
25
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28 import java.sql.SQLException;
29
30 import java.util.Properties;
31
32
33
34 /***
35 * Simple Connection provider. <br> provides non-pooled connections.
36 *
37 * @author Luca Fossato
38 */
39 public class SimpleConnectionProvider extends AbstractConnectionProvider {
40 /***
41 * Default constructor.
42 *
43 * @exception Exception Description of the Exception
44 * @throws Exception because of the <code>throws Exception</code> clause of
45 * the <code>init</code> method.
46 */
47 public SimpleConnectionProvider() throws Exception {
48 super();
49 }
50
51 /***
52 * Get a JDBC Connection
53 *
54 * @return a JDBC Connection
55 *
56 * @exception SQLException Description of the Exception
57 */
58 protected Connection getConnection() throws SQLException {
59 Properties props = getPrefs()
60 .getProperties();
61 Connection con = null;
62
63
64 if ((props != null) && !props.isEmpty()) {
65 props.put("user", getPrefs().getUser());
66 props.put("password", getPrefs().getPassword());
67 con = DriverManager.getConnection(getPrefs().getJdbcURL(), props);
68 }
69
70 else {
71 con = DriverManager.getConnection(getPrefs().getJdbcURL(),
72 getPrefs().getUser(),
73 getPrefs().getPassword());
74 }
75
76 return con;
77 }
78
79
80 /***
81 * Initialize the ConnectionProvider.
82 *
83 * @throws Exception if any error occurs
84 */
85 protected void init() throws Exception {
86 Class.forName(getPrefs().getJdbcDriver())
87 .newInstance();
88 }
89 }