我需要连接到两个不同的数据库从我的代码。第一个是hive数据库,另一个是oracle。为此,我需要加载两个不同的驱动程序,一个用于hive,另一个用于oracle。以下是我所做的:
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("Driver Found");
Connection connection = DriverManager.getConnection(
"jdbc:hive2://10.8.219.36:10000/default", "lab", "lab");
System.out.println("Connection established");
System.out.println("------------------");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Found");
Connection connection1 = DriverManager.getConnection(
"jdbc:oracle:thin:@97.253.16.117:1521:NATTDB11",
"CDR_LOADER", "CDR_LOADER");
System.out.println("Connection established");
当我运行上面的代码时,得到的错误是:
Driver Found
Connection established
------------------
Driver Found
java.lang.IllegalArgumentException: Bad URL format
at org.apache.hive.jdbc.Utils.parseURL(Utils.java:185)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:84)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Demo.main(Demo.java:17)
我该怎么做?先谢谢你。
1条答案
按热度按时间lxkprmvk1#
尝试使用以下方法显式注册两个驱动程序:
然后测试两种连接类型。