mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34:38 +02:00
8211295: DriverManager.getConnection fails when called from com.sun.rowset.JdbcRowSetImpl
Reviewed-by: mchung, alanb
This commit is contained in:
parent
4374820705
commit
c925556ec4
3 changed files with 85 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -652,7 +652,7 @@ public class DriverManager {
|
||||||
* can be loaded from here.
|
* can be loaded from here.
|
||||||
*/
|
*/
|
||||||
ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
|
ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
|
||||||
if (callerCL == null) {
|
if (callerCL == null || callerCL == ClassLoader.getPlatformClassLoader()) {
|
||||||
callerCL = Thread.currentThread().getContextClassLoader();
|
callerCL = Thread.currentThread().getContextClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -43,6 +43,8 @@ import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class StubConnection implements Connection {
|
public class StubConnection implements Connection {
|
||||||
|
|
||||||
|
private boolean autoCommit = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
@ -65,12 +67,14 @@ public class StubConnection implements Connection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
System.out.println("**** in StubConnection.setAutoCommit");
|
||||||
|
this.autoCommit = autoCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getAutoCommit() throws SQLException {
|
public boolean getAutoCommit() throws SQLException {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
System.out.println("*** in StubConnection.getAutoCommit");
|
||||||
|
return autoCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
package test.rowset.jdbcrowset;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import javax.sql.rowset.JdbcRowSet;
|
||||||
|
import javax.sql.rowset.RowSetFactory;
|
||||||
|
import javax.sql.rowset.RowSetProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import util.BaseTest;
|
||||||
|
import util.StubDriver;
|
||||||
|
|
||||||
|
public class JdbcRowSetDriverManagerTest extends BaseTest {
|
||||||
|
|
||||||
|
// URL that the StubDriver recognizes
|
||||||
|
private final static String StubDriverURL = "jdbc:tennis:boy";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that JDBCRowSetImpl can connect to a JDBC driver that is
|
||||||
|
* register by DriverManager.
|
||||||
|
*/
|
||||||
|
@Test(enabled = true)
|
||||||
|
public void test0000() throws SQLException {
|
||||||
|
|
||||||
|
DriverManager.registerDriver(new StubDriver());
|
||||||
|
|
||||||
|
// Show that the StubDriver is loaded and then call setAutoCommit on
|
||||||
|
// the returned Connection
|
||||||
|
dumpRegisteredDrivers();
|
||||||
|
Connection con = DriverManager.getConnection(StubDriverURL, "userid", "password");
|
||||||
|
con.setAutoCommit(true);
|
||||||
|
|
||||||
|
// Have com.sun.rowset.JdbcRowSetImpl create a Connection and
|
||||||
|
// then call setAutoCommit
|
||||||
|
RowSetFactory rsf = RowSetProvider.newFactory();
|
||||||
|
JdbcRowSet jrs = rsf.createJdbcRowSet();
|
||||||
|
jrs.setUrl(StubDriverURL);
|
||||||
|
jrs.setUsername("userid");
|
||||||
|
jrs.setPassword("password");
|
||||||
|
|
||||||
|
jrs.setAutoCommit(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dumpRegisteredDrivers() {
|
||||||
|
System.out.println("+++ Loaded Drivers +++");
|
||||||
|
System.out.println("++++++++++++++++++++++++");
|
||||||
|
DriverManager.drivers()
|
||||||
|
.forEach(d
|
||||||
|
-> System.out.println("+++ Driver:" + d + " "
|
||||||
|
+ d.getClass().getClassLoader()));
|
||||||
|
System.out.println("++++++++++++++++++++++++");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue