KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > sql > SimpleSqlConnectionSource


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.contrib.table.model.sql;
16
17 import java.sql.Connection JavaDoc;
18 import java.sql.DriverManager JavaDoc;
19 import java.sql.SQLException JavaDoc;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 /**
25  * @author mindbridge
26  */

27 public class SimpleSqlConnectionSource implements ISqlConnectionSource
28 {
29     private static final Log LOG = LogFactory.getLog(SimpleSqlConnectionSource.class);
30
31     private String JavaDoc m_strUrl;
32
33     private String JavaDoc m_strUser;
34
35     private String JavaDoc m_strPwd;
36
37     public SimpleSqlConnectionSource(String JavaDoc strUrl)
38     {
39         this(strUrl, null, null);
40     }
41
42     public SimpleSqlConnectionSource(String JavaDoc strUrl, String JavaDoc strUser, String JavaDoc strPwd)
43     {
44         m_strUrl = strUrl;
45         m_strUser = strUser;
46         m_strPwd = strPwd;
47     }
48
49     /**
50      * @see org.apache.tapestry.contrib.table.model.sql.ISqlConnectionSource#obtainConnection()
51      */

52     public Connection JavaDoc obtainConnection() throws SQLException JavaDoc
53     {
54         if (m_strUser == null)
55             return DriverManager.getConnection(m_strUrl);
56
57         return DriverManager.getConnection(m_strUrl, m_strUser, m_strPwd);
58     }
59
60     /**
61      * @see org.apache.tapestry.contrib.table.model.sql.ISqlConnectionSource#returnConnection(Connection)
62      */

63     public void returnConnection(Connection JavaDoc objConnection)
64     {
65         try
66         {
67             objConnection.close();
68         }
69         catch (SQLException JavaDoc e)
70         {
71             LOG.warn("Could not close connection", e);
72         }
73     }
74
75 }
Popular Tags