我試圖連接到一個數據庫Hive2但我發現了以下錯誤:Hive2 JDBC錯誤
java.lang.NoSuchFieldError的:HIVE_SERVER2_TRANSPORT_MODE
這裏是我試圖運行代碼。基本上,我只是想用一個用戶自定義查詢的結果連接到hive2 DATABSE並填充一個JTable:
import java.sql.Connection;
import org.apache.hadoop.hive.jdbc.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import javax.swing.JTable;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.Cursor;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
import org.apache.hive.jdbc.*;
import org.apache.hive.jdbc.Utils;
import org.apache.hive.*;
import org.apache.hive.service.*;
import org.apache.http.*;
import org.apache.hive.service.CompositeService;
import org.apache.hive.service.cli.CLIService;
import org.apache.hive.service.cli.thrift.*;
import org.apache.hive.service.server.*;
import org.apache.hadoop.hive.conf.HiveConf;
public class SQLSelect extends javax.swing.JFrame {
/**
* Creates new form SQLSelect
*/
ResultSet r;
Statement s;
public SQLSelect() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
setCursor(cursor);
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
//Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.getMessage();
}
try {
String locationString = "jdbc:hive2://" + jTextField1.getText() + ":" + jTextField2.getText();
String userString = jTextField3.getText();
char password[] = jPasswordField1.getPassword();
String pString = new String(password);
System.out.println(locationString + userString + pString);
Connection conn = DriverManager.getConnection(locationString,userString,pString);
//Connection conn = DriverManager.getConnection("jdbc:hive://76.99.192.2:9999","user","password");
s = conn.createStatement();
r = s.executeQuery(jTextArea1.getText());
//System.out.println(r.getNString(1));
}
catch (Exception e)
{
setCursor(Cursor.DEFAULT_CURSOR);
JOptionPane.showMessageDialog(null, e.getMessage(), "SQL Error", JOptionPane.ERROR_MESSAGE);
jLabel9.setText(e.getMessage());
}
try {
MainPanel resultsPanel = new jdbctohive.MainPanel();
resultsPanel.jTable1.setModel(DbUtils.resultSetToTableModel(r));
resultsPanel.setTitle("Hive SQL Management Studio");
resultsPanel.setVisible(true);
setCursor(Cursor.DEFAULT_CURSOR);
this.setVisible(false);
}
catch (Exception e)
{
setCursor(Cursor.DEFAULT_CURSOR);
}
任何幫助,將不勝感激!