1 34 package net.myvietnam.mvncore.info; 35 36 import java.sql.Connection ; 37 import java.sql.DatabaseMetaData ; 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 databaseProductName; 48 private String databaseProductVersion; 49 private String databaseUrl; 50 private String databaseUsername; 51 private String driverName; 52 private String driverVersion; 53 54 private String errorMessage; 55 56 public DatabaseInfo() { 57 Connection connection = null; 58 try { 59 connection = DBUtils.getConnection(); 60 DatabaseMetaData 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 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 getDatabaseProductName() { 76 return databaseProductName; 77 } 78 79 public String getDatabaseProductVersion() { 80 return databaseProductVersion; 81 } 82 83 public String getDatabaseUrl() { 84 return databaseUrl; 85 } 86 87 public String getDatabaseUsername() { 88 return databaseUsername; 89 } 90 91 public String getDriverName() { 92 return driverName; 93 } 94 95 public String getDriverVersion() { 96 return driverVersion; 97 } 98 99 public String getErrorMessage() { 100 return errorMessage; 101 } 102 } 103 | Popular Tags |