View | Details | Raw Unified | Return to bug 48773
Collapse All | Expand All

(-)impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java (-13 / +27 lines)
Lines 19-26 Link Here
19
19
20
import java.io.PrintWriter;
20
import java.io.PrintWriter;
21
import java.sql.Connection;
21
import java.sql.Connection;
22
import java.sql.Driver;
22
import java.sql.DriverManager;
23
import java.sql.DriverManager;
23
import java.sql.SQLException;
24
import java.sql.SQLException;
25
import java.util.Properties;
24
26
25
import javax.sql.DataSource;
27
import javax.sql.DataSource;
26
28
Lines 34-40 Link Here
34
 * @author Hans Bergsten
36
 * @author Hans Bergsten
35
 */
37
 */
36
public class DataSourceWrapper implements DataSource {
38
public class DataSourceWrapper implements DataSource {
37
    private String driverClassName;
39
    private Driver driver;
38
    private String jdbcURL;
40
    private String jdbcURL;
39
    private String userName;
41
    private String userName;
40
    private String password;
42
    private String password;
Lines 43-50 Link Here
43
        throws ClassNotFoundException, InstantiationException, 
45
        throws ClassNotFoundException, InstantiationException, 
44
            IllegalAccessException {
46
            IllegalAccessException {
45
47
46
        this.driverClassName = driverClassName;
47
48
        //get the classloader
48
        //get the classloader
49
        ClassLoader cl;
49
        ClassLoader cl;
50
        SecurityManager sm = System.getSecurityManager();
50
        SecurityManager sm = System.getSecurityManager();
Lines 57-63 Link Here
57
        }
57
        }
58
        //done getting classloader
58
        //done getting classloader
59
    
59
    
60
        Class.forName(driverClassName, true, cl).newInstance();
60
        Object instance = Class.forName(driverClassName, true, cl).newInstance();
61
        if (instance instanceof Driver) {
62
            driver = (Driver) instance;
63
        }
61
    }
64
    }
62
65
63
    public void setJdbcURL(String jdbcURL) {
66
    public void setJdbcURL(String jdbcURL) {
Lines 77-92 Link Here
77
     * set properties.
80
     * set properties.
78
     */
81
     */
79
    public Connection getConnection() throws SQLException {
82
    public Connection getConnection() throws SQLException {
80
	Connection conn = null;
83
        Connection conn = null;
81
	if (userName != null) {
84
        if (driver != null) {
82
	    conn = DriverManager.getConnection(jdbcURL, userName, password);
85
            Properties props = new Properties();
83
	}
86
            if (userName != null) {
84
	else {
87
                props.put("user", userName);
85
	    conn = DriverManager.getConnection(jdbcURL);
88
            }
86
	}
89
            if (password != null) {
87
	return conn;
90
                props.put("password", password);
91
            }
92
            conn = driver.connect(jdbcURL, props);
93
        }
94
        if (conn == null) {
95
            if (userName != null) {
96
                conn = DriverManager.getConnection(jdbcURL, userName, password);
97
            } else {
98
                conn = DriverManager.getConnection(jdbcURL);
99
            }
100
        }
101
        return conn;
88
    }
102
    }
89
103
    
90
    /**
104
    /**
91
     * Always throws a SQLException. Username and password are set
105
     * Always throws a SQLException. Username and password are set
92
     * in the constructor and can not be changed.
106
     * in the constructor and can not be changed.

Return to bug 48773