1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package test.rowset.jdbcrowset; 24 25 import java.sql.Connection; 26 import java.sql.DriverManager; 27 import java.sql.SQLException; 28 import javax.sql.rowset.JdbcRowSet; 29 import javax.sql.rowset.RowSetFactory; 30 import javax.sql.rowset.RowSetProvider; 31 import org.testng.annotations.Test; 32 import util.BaseTest; 33 import util.StubDriver; 34 35 public class JdbcRowSetDriverManagerTest extends BaseTest { 36 37 // URL that the StubDriver recognizes 38 private final static String StubDriverURL = "jdbc:tennis:boy"; 39 40 /** 41 * Validate that JDBCRowSetImpl can connect to a JDBC driver that is 42 * register by DriverManager. 43 */ 44 @Test(enabled = true) 45 public void test0000() throws SQLException { 46 47 DriverManager.registerDriver(new StubDriver()); 48 49 // Show that the StubDriver is loaded and then call setAutoCommit on 50 // the returned Connection 51 dumpRegisteredDrivers(); 52 Connection con = DriverManager.getConnection(StubDriverURL, "userid", "password"); 53 con.setAutoCommit(true); 54 55 // Have com.sun.rowset.JdbcRowSetImpl create a Connection and 56 // then call setAutoCommit 57 RowSetFactory rsf = RowSetProvider.newFactory(); 58 JdbcRowSet jrs = rsf.createJdbcRowSet(); 59 jrs.setUrl(StubDriverURL); 60 jrs.setUsername("userid"); 61 jrs.setPassword("password"); 62 63 jrs.setAutoCommit(true); 64 } 65 66 private static void dumpRegisteredDrivers() { 67 System.out.println("+++ Loaded Drivers +++"); 68 System.out.println("++++++++++++++++++++++++"); 69 DriverManager.drivers() 70 .forEach(d 71 -> System.out.println("+++ Driver:" + d + " " 72 + d.getClass().getClassLoader())); 73 System.out.println("++++++++++++++++++++++++"); 74 75 } 76 }