KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > piratepete > util > db > DBWorker


1 package com.piratepete.util.db;
2
3
4 import java.sql.*;
5
6 /**
7  * DBWorker Class
8  * Copyright (C) 2003 David L. Whitehurst<p>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.<p>
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.<p>
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<p>
23  *
24  * <a HREF="http://www.piratepetesoftware.com">piratepetesoftware.com</a><br>
25  * <a HREF="mailto:dlwhitehurst@comcast.net">dlwhitehurst@comcast.net</a>
26  *
27  * @version 1.0a
28  */

29 public class DBWorker {
30    private Connection conn = null;
31    
32     
33     public boolean isConnected() {
34         return true;
35     }
36     
37     public Connection getConnection() {
38         return conn;
39         
40     }
41     public void connect(String JavaDoc classname, String JavaDoc url) {
42
43         try {
44
45             // Load database driver
46
// e.g. Class.forName("org.gjt.mm.mysql.Driver");
47
Class.forName(classname);
48             
49             // Make connection
50
conn = DriverManager.getConnection(url);
51             
52             // test
53
if (!conn.isClosed()) {
54                 System.out.println("jdbc connection is open");
55             }
56             
57             // close for test, leave open for debug
58
//conn.close();
59
} catch (SQLException sqlex) {
60             sqlex.printStackTrace();
61         } catch (ClassNotFoundException JavaDoc cnfe) {
62             cnfe.printStackTrace();
63         }
64             
65     }
66 }
67
Popular Tags