我正在尝试连接到 Hive2 数据库,但出现以下错误:
java.lang.NoSuchFieldError:HIVE_SERVER2_TRANSPORT_MODE
这是我要运行的代码。基本上,我只是想连接到 hive2 数据库并使用用户定义的查询的结果填充 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);
}
任何帮助将非常感激!