KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > conprovider > SimpleConnectionProvider


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/conprovider/SimpleConnectionProvider.java,v 1.7 2004/08/18 12:25:57 hkollmann Exp $
3  * $Revision: 1.7 $
4  * $Date: 2004/08/18 12:25:57 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.conprovider;
25
26 import java.sql.Connection JavaDoc;
27 import java.sql.DriverManager JavaDoc;
28 import java.sql.SQLException JavaDoc;
29
30 import java.util.Properties JavaDoc;
31
32
33
34 /**
35  * Simple Connection provider. <br> provides non-pooled connections.
36  *
37  * @author Luca Fossato
38  */

39 public class SimpleConnectionProvider extends ConnectionProvider {
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 JavaDoc {
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 JavaDoc getConnection() throws SQLException JavaDoc {
59       Properties JavaDoc props = getPrefs()
60                             .getProperties();
61       Connection JavaDoc con = null;
62
63       // uses custom jdbc properties;
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       // "plain" flavour;
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 JavaDoc {
86       Class.forName(getPrefs().getJdbcDriver())
87            .newInstance();
88    }
89 }
90
Popular Tags