KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > jca > SimpleDataSource


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.jca;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.sql.Connection JavaDoc;
22 import java.sql.DriverManager JavaDoc;
23 import java.sql.SQLException JavaDoc;
24
25 import javax.sql.DataSource JavaDoc;
26
27 /**
28  *
29  * @author S.Chassande-Barrioz
30  */

31 public class SimpleDataSource implements DataSource JavaDoc {
32     private String JavaDoc url;
33     private String JavaDoc user;
34     private String JavaDoc password;
35     private PrintWriter JavaDoc pw;
36     int to = 0;
37
38     public SimpleDataSource(String JavaDoc driver,
39                             String JavaDoc url,
40                             String JavaDoc user,
41                             String JavaDoc password) throws Exception JavaDoc {
42         Class.forName(driver);
43         this.url = url;
44         this.user = user;
45         this.password = password;
46     }
47
48     public Connection JavaDoc getConnection() throws SQLException JavaDoc {
49         return DriverManager.getConnection(url, user, password);
50     }
51
52     public Connection JavaDoc getConnection(String JavaDoc username, String JavaDoc password)
53             throws SQLException JavaDoc {
54         return DriverManager.getConnection(url, username, password);
55     }
56
57     public PrintWriter JavaDoc getLogWriter() throws SQLException JavaDoc {
58         return pw;
59     }
60
61     public void setLogWriter(PrintWriter JavaDoc out) throws SQLException JavaDoc {
62         pw = out;
63     }
64
65     public void setLoginTimeout(int seconds) throws SQLException JavaDoc {
66         to = seconds;
67     }
68
69     public int getLoginTimeout() throws SQLException JavaDoc {
70         return to;
71     }
72 }
73
Popular Tags