我需要从我的代码连接到两个不同的数据库。首先是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)
我该怎么做?提前谢谢。
答案 0 :(得分:1)
尝试使用以下方法显式注册两个驱动程序:
<table id="tabla">
<thead>
<tr>
<th>producto</th>
<th>entry</th>
<th>exit</th>
<th>stock</th>
</tr>
</thead>
<tbody>
<tr><td class="opening balance">10</td></tr>
<tr>
<td class="info">TP031</td>
<td class="entry">4</td>
<td class="exit">0</td>
<td class="stock">14</td>
</tr>
<tr>
<td class="info">SI0352</td>
<td id="entry">0</td>
<td class="exit">3</td>
<td class="stock">11</td>
</tr>
<tr>
<td class="info">MP4012</td>
<td class="entry">0</td>
<td class="exit">3</td>
<td class="stock">9</td>
</tr>
</tbody>
</table>
然后测试两种连接类型。