我想使用 JDBC 在 Hive 中创建表。这是我试过的代码,
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveClient {
private static String driverName = "com.mysql.jdbc.Driver";
public static void main(String[] args) {
Connection con=null;
// Register driver and create driver instance
try {
Class.forName(driverName);
// get connection
con = DriverManager.getConnection("jdbc:mysql://sandbox-hdp.hortonworks.com/hive?createDatabaseIfNotExist=true/userdb", "root", "dc123");
// create statement
Statement stmt = con.createStatement();
// execute statement
stmt.executeQuery("CREATE TABLE IF NOT EXISTS "
+" employee ( eid int, name String, "
+" salary String, destignation String)"
+" COMMENT ‘Employee details’"
+" ROW FORMAT DELIMITED"
+" FIELDS TERMINATED BY ‘\t’"
+" LINES TERMINATED BY ‘\n’"
+" STORED AS TEXTFILE;");
System.out.println(" Table employee created.");
con.close();
}catch(Exception e){
System.out.println(e);
}
}
}
该程序显示异常:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
请帮我解决这个问题。