1 16 17 package org.apache.taglibs.standard.tag.common.sql; 18 19 import java.io.PrintWriter ; 20 import java.sql.Connection ; 21 import java.sql.DriverManager ; 22 import java.sql.SQLException ; 23 24 import javax.sql.DataSource ; 25 26 import org.apache.taglibs.standard.resources.Resources; 27 28 29 35 public class DataSourceWrapper implements DataSource { 36 private String driverClassName; 37 private String jdbcURL; 38 private String userName; 39 private String password; 40 41 public void setDriverClassName(String driverClassName) 42 throws ClassNotFoundException , InstantiationException , 43 IllegalAccessException { 44 45 this.driverClassName = driverClassName; 46 Class.forName(driverClassName, true, 47 Thread.currentThread().getContextClassLoader()).newInstance(); 48 } 49 50 public void setJdbcURL(String jdbcURL) { 51 this.jdbcURL = jdbcURL; 52 } 53 54 public void setUserName(String userName) { 55 this.userName = userName; 56 } 57 58 public void setPassword(String password) { 59 this.password = password; 60 } 61 62 66 public Connection getConnection() throws SQLException { 67 Connection conn = null; 68 if (userName != null) { 69 conn = DriverManager.getConnection(jdbcURL, userName, password); 70 } 71 else { 72 conn = DriverManager.getConnection(jdbcURL); 73 } 74 return conn; 75 } 76 77 81 public Connection getConnection(String username, String password) 82 throws SQLException { 83 throw new SQLException (Resources.getMessage("NOT_SUPPORTED")); 84 } 85 86 89 public int getLoginTimeout() throws SQLException { 90 throw new SQLException (Resources.getMessage("NOT_SUPPORTED")); 91 } 92 93 96 public PrintWriter getLogWriter() throws SQLException { 97 throw new SQLException (Resources.getMessage("NOT_SUPPORTED")); 98 } 99 100 103 public void setLoginTimeout(int seconds) throws SQLException { 104 throw new SQLException (Resources.getMessage("NOT_SUPPORTED")); 105 } 106 107 110 public synchronized void setLogWriter(PrintWriter out) throws SQLException { 111 throw new SQLException (Resources.getMessage("NOT_SUPPORTED")); 112 } 113 114 115 } 116 | Popular Tags |