1 25 package org.objectweb.easybeans.tests.common.db; 26 27 import java.io.PrintWriter ; 28 import java.io.Serializable ; 29 import java.sql.Connection ; 30 import java.sql.DriverManager ; 31 import java.sql.SQLException ; 32 import java.util.Hashtable ; 33 34 import javax.sql.DataSource ; 35 36 import org.objectweb.easybeans.log.JLog; 37 import org.objectweb.easybeans.log.JLogFactory; 38 39 45 public class DBManager implements DataSource , Serializable { 46 47 50 private static final long serialVersionUID = 1208377914757260026L; 51 52 55 public static final Integer JDBC_DRIVER = new Integer (1); 56 57 60 public static final Integer URL = new Integer (2); 61 62 65 public static final Integer LOGIN = new Integer (3); 66 67 70 public static final Integer PASSWD = new Integer (4); 71 72 75 private String strURL = null; 76 77 80 private String strLogin = null; 81 82 85 private String strPasswd = null; 86 87 90 private String strJDBCDriver = null; 91 92 95 private static JLog logger = JLogFactory.getLog(DBManager.class); 96 97 103 public DBManager(final Hashtable <Integer , String > dbParameters) throws ClassNotFoundException { 104 105 Class.forName(dbParameters.get(JDBC_DRIVER)); 106 strURL = dbParameters.get(URL); 107 strJDBCDriver = dbParameters.get(JDBC_DRIVER); 108 strLogin = dbParameters.get(LOGIN); 109 strPasswd = dbParameters.get(PASSWD); 110 } 111 112 117 public Connection getConnection() throws SQLException { 118 try{ 119 Class.forName(strJDBCDriver); 120 }catch(Exception e){ 121 logger.debug("Cannot uses the driver {0}", e); 122 } 123 return DriverManager.getConnection(strURL, strLogin, strPasswd); 124 125 } 126 127 134 public Connection getConnection(final String username, final String password) throws SQLException { 135 return DriverManager.getConnection(strURL, username, password); 136 } 137 138 143 public int getLoginTimeout() throws SQLException { 144 throw new SQLException ("Not implemented"); 145 } 146 147 152 public PrintWriter getLogWriter() throws SQLException { 153 throw new SQLException ("Not implemented"); 154 } 155 156 161 public void setLoginTimeout(final int seconds) throws SQLException { 162 throw new SQLException ("Not implemented"); 163 } 164 165 170 public void setLogWriter(final PrintWriter out) throws SQLException { 171 throw new SQLException ("Not implemented"); 172 } 173 174 } 175 | Popular Tags |