如果你不使用 dbcp 那么你可以这样做
class Test
static Driver driver5;
static Driver driver6;
static void init() throws Exception {
ClassLoader cl5 = new URLClassLoader(new URL[] { new URL("file:lib/ojdbc15.jar") });
driver5 = (Driver) cl5.loadClass("oracle.jdbc.driver.OracleDriver").newInstance();
ClassLoader cl6 = new URLClassLoader(new URL[] { new URL("file:lib/ojdbc6.jar") });
driver6 = (Driver) cl6.loadClass("oracle.jdbc.driver.OracleDriver").newInstance();
}
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put("user", "user");
props.put("password", "pwd");
String url = "jdbc:oracle:thin:@host:1529:sid";
Connection conn5 = driver5.connect(url, props);
Connection conn6 = driver6.connect(url, props);
}
Run Code Online (Sandbox Code Playgroud)
请注意,ojdbc15.jar 和 ojdbc6.jar 不应该位于 java 类路径上,它们对于应用程序类加载器应该是不可见的
| 归档时间: |
|
| 查看次数: |
1127 次 |
| 最近记录: |