Created 06-29-2017 06:56 PM
I have the hive-jdbc.jar file but still the compiler cant find it .
-rw-r--r-- 1 root root 110242 Nov 29 2016 /usr/hdp/2.5.3.0-37/hive2/lib/hive-jdbc-2.1.0.2.5.3.0-37.jar [hdfs@hadoop1 ~]$ [hdfs@hadoop1 ~]$ javac -cp /usr/hdp/2.5.3.0-37/hive2/lib/hive-jdbc.jar HiveAlterRenameTo.java HiveAlterRenameTo.java:13: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown Class.forName(driverName); ^
code is as below:
[hdfs@hadoop1 ~]$ more HiveAlterRenameTo.java import java.sql.SQLException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.sql.DriverManager; public class HiveAlterRenameTo { private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; public static void main(String[] args) throws SQLException { // Register driver and create driver instance Class.forName(driverName); // get connection Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", ""); // create statement Statement stmt = con.createStatement(); // execute statement stmt.executeQuery("ALTER TABLE tab1_ORC RENAME TO tab1;"); System.out.println("Table Renamed Successfully"); con.close(); } }
Created 06-29-2017 07:11 PM
@Sami Ahmad Can you try
javac -cp `hadoop classpath`:/usr/hdp/2.5.3.0-37/hive2/lib/* HiveAlterRenameTo.java
Created 06-29-2017 07:21 PM
still the same error
[hdfs@hadoop1 ~]$ env | grep HADOOP HADOOP_CLASSPATH=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-0.b15.el6_8.x86_64/lib/tools.jar [hdfs@hadoop1 ~]$ [hdfs@hadoop1 ~]$ [hdfs@hadoop1 ~]$ javac -cp $HADOOP_CLASSPATH:/usr/hdp/2.5.3.0-37/hive2/lib/* HiveAlterRenameTo.java HiveAlterRenameTo.java:13: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown Class.forName(driverName); ^ 1 error [hdfs@hadoop1 ~]$
Created 06-30-2017 04:52 AM
Your driverName is set incorrectly, it should be "org.apache.hive.jdbc.HiveDriver".
Created 06-30-2017 06:28 PM
still same error
[hdfs@hadoop1 ~]$ grep "driverName =" *.java HiveAlterRenameTo.java: private static String driverName = "org.apache.hive.jdbc.HiveDriver"; [hdfs@hadoop1 ~]$ echo $HADOOP_CLASSPATH /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-0.b15.el6_8.x86_64/lib/tools.jar [hdfs@hadoop1 ~]$ [hdfs@hadoop1 ~]$ javac -cp $HADOOP_CLASSPATH:/usr/hdp/2.5.3.0-37/hive2/lib/* HiveAlterRenameTo.java HiveAlterRenameTo.java:13: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown Class.forName(driverName); ^ 1 error [
Created 07-05-2017 07:36 PM
You need to catch the appropriate exception as the error indicates. Here is an example:
try { Class.forName(driverName); } catch (ClassNotFoundException ex) { ex.printStackTrace(); }
Created 07-05-2017 07:38 PM
Duplicate Thread Answered Here:
https://community.hortonworks.com/questions/110307/please-help-compile.html#answer-110322