KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > info > DatabaseInfo


1 /*
2  * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/info/DatabaseInfo.java,v 1.10 2006/04/15 02:59:19 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.10 $
5  * $Date: 2006/04/15 02:59:19 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding MyVietnam and MyVietnam CoreLib
12  * MUST remain intact in the scripts and source code.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  *
28  * Correspondence and Marketing Questions can be sent to:
29  * info at MyVietnam net
30  *
31  * @author: Minh Nguyen
32  * @author: Mai Nguyen
33  */

34 package net.myvietnam.mvncore.info;
35
36 import java.sql.Connection JavaDoc;
37 import java.sql.DatabaseMetaData JavaDoc;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import net.myvietnam.mvncore.db.DBUtils;
42
43 public class DatabaseInfo {
44
45     private static Log log = LogFactory.getLog(DatabaseInfo.class);
46
47     private String JavaDoc databaseProductName;
48     private String JavaDoc databaseProductVersion;
49     private String JavaDoc databaseUrl;
50     private String JavaDoc databaseUsername;
51     private String JavaDoc driverName;
52     private String JavaDoc driverVersion;
53
54     private String JavaDoc errorMessage;
55
56     public DatabaseInfo() {
57         Connection JavaDoc connection = null;
58         try {
59             connection = DBUtils.getConnection();
60             DatabaseMetaData JavaDoc dbmd = connection.getMetaData();
61             databaseUrl = dbmd.getURL();
62             databaseUsername = dbmd.getUserName();
63             databaseProductName = dbmd.getDatabaseProductName();
64             databaseProductVersion = dbmd.getDatabaseProductVersion();
65             driverName = dbmd.getDriverName();
66             driverVersion = dbmd.getDriverVersion();
67         } catch (Exception JavaDoc ex) {
68             log.error("Error when access database info", ex);
69             errorMessage = ex.getMessage();
70         } finally {
71             DBUtils.closeConnection(connection);
72         }
73     }
74
75     public String JavaDoc getDatabaseProductName() {
76         return databaseProductName;
77     }
78
79     public String JavaDoc getDatabaseProductVersion() {
80         return databaseProductVersion;
81     }
82
83     public String JavaDoc getDatabaseUrl() {
84         return databaseUrl;
85     }
86
87     public String JavaDoc getDatabaseUsername() {
88         return databaseUsername;
89     }
90
91     public String JavaDoc getDriverName() {
92         return driverName;
93     }
94
95     public String JavaDoc getDriverVersion() {
96         return driverVersion;
97     }
98
99     public String JavaDoc getErrorMessage() {
100         return errorMessage;
101     }
102 }
103
Popular Tags