How to insert a java Blob data into Hive table?

时间:2018-02-05 12:50:35

标签: java hadoop jdbc hive

I am using hive JDBC connection to insert data int hive(I do understand single record insertion is not good) . But while I am using setBlob() method of preparedStatement , it says method is not there .

Is there any other way to insert Blob data into hive grammatically in java .

Code:-

File ImgPath = new File("C:\\Users\\ezswapr\\IdeaProjects\\DataStructure\\org.priyaranjan.ds\\src\\output\\"+"Desert.jpg");
            FileInputStream fileinput = new FileInputStream(ImgPath);


            System.out.println("length of the file is :" + (int)ImgPath.length());
            String query = "INSERT INTO image(data) VALUES(?);";
            Statement stmt = hiveconnection.createStatement();
            //stmt.executeQuery("INSERT INTO image(data) VALUES(?);");
            PreparedStatement p = hiveconnection.prepareStatement(query);
            byte[] bytearray = IOUtils.toByteArray(fileinput);
            Blob blob = new javax.sql.rowset.serial.SerialBlob(bytearray);

            p.setBlob(1,blob);

            p.execute();

            System.out.println("Closing the connections");
            hiveconnection.close();

Error:-

log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
length of the file is :845941
Exception in thread "main" java.sql.SQLException: Method not supported
    at org.apache.hive.jdbc.HivePreparedStatement.setBlob(HivePreparedStatement.java:305)
    at treeJava.Smpblobhive.main(Smpblobhive.java:69)

Process finished with exit code 1

0 个答案:

没有答案