Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
linenumberstrue
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SpringJdbcTestJdbcAddBatchTest {

    public static void main(String[] args) throws SQLException {
        com.cloudera.impala.jdbc.DataSource ds = new com.cloudera.impala.jdbc.DataSource();
        ds.setURL("jdbc:impala://10.0.1.71:21050/default");
        ds.setUserID("impala");
        ds.setPassword("impala");
        ds.setCustomProperty("AuthMech", "0");

        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement();

        stmt.addBatch("SET SYNC_DDL=1");
        stmt.addBatch("CREATE TABLE STUDENT(STUDENT_ID STRING) PARTITION BY HASH (STUDENT_ID) PARTITIONS 10 STORED AS KUDU");
        stmt.addBatch("REFRESH STUDENT");
        stmt.addBatch("INSERT INTO STUDENT (STUDENT_ID) VALUES('S101')");
        stmt.addBatch("INSERT INTO STUDENT (STUDENT_ID) VALUES('S102')");
        stmt.addBatch("INSERT INTO STUDENT (STUDENT_ID) VALUES('S103')");
        stmt.addBatch("INSERT INTO STUDENT (STUDENT_ID) VALUES('S104')");

        stmt.executeBatch();

        ResultSet rs = stmt.executeQuery("SELECT * FROM STUDENT");
        while (rs.next()) {
            System.out.println(rs.getString(0));
        }

        stmt.close();
        conn.close();
    }

}

...