Hive2 JDBC错误

时间:2013-10-28 19:32:26

标签: java swing jdbc hadoop hive

我正在尝试连接到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);
                }

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我终于能够连接了。我之前的声明建议使用“; auth = noSasl”,结果证明这是错误的。经过多次尝试,这是最终有效的代码。当我在windows中工作时,我遇到了需要winutils.exe的Hadoop Win版本的问题。由于HortonWorks在其产品的1.3版本中有Win实现,因此我将其下载并从.MSI文件中提取文件。如果在linux中工作,你可能不需要这个。我找到的一个键是实现jdbc和hadoop日志记录,因为没有这些,我简单地被卡在getConnection上永远不会返回...但是,有一些潜在的错误,我只是假设word返回为stacktrace,但没有。祝好运。

帮助记录的文件:C:/temp/log.properties .LEVEL =严重

oracle.jdbc.level = INFO

oracle.jdbc.handlers = java.util.logging.ConsoleHandler

java.util.logging.ConsoleHandler.level = INFO

java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

    Logger logger = org.apache.log4j.Logger.getRootLogger();

    logger.setLevel(Level.INFO);
    try {
        Class.forName("org.apache.hive.jdbc.HiveDriver");

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (Exception e){
        e.printStackTrace();
    }
    try{
        File propFile = new File("C:/temp/log.properties");
        LogManager logManager = LogManager.getLogManager();
        logManager.readConfiguration(new FileInputStream(propFile));

        DriverManager.setLogWriter(new PrintWriter(System.err));

        Logger l2 = Logger.getLogger("org.apache.hadoop.util.Shell");
        Logger l3 = Logger.getLogger("java.sql.DriverManager");
        Layout simple = new SimpleLayout();
        Appender newAppender = new ConsoleAppender(simple);
        logger.addAppender(newAppender);
        logger.setLevel(Level.ALL);
        l2.setLevel(Level.ALL);
        l2.addAppender(newAppender);
        l3.setLevel(Level.ALL);
        l3.addAppender(newAppender);

        System.setProperty("HADOOP_HOME", "C:\\Development\\hadoopCore\\hadoop-2.2.0");
        logger.debug("Logging works");
        Connection con = DriverManager.getConnection("jdbc:hive2://192.168.218.152:10000/default", "", "");//Hortonworks Hive ODBC Driver
        if (con != null)
            con.close();
        System.out.println("got the connection");