使用 Simba Spark JDBC 驱动程序的多语句查询

问题描述

我正在尝试使用 jdbc 连接调用 Databricks 集群。在这里,我想发送多个语句。一种是“缓存表选择”,另一种是选择创建的表。

我一直无法理解一系列事情,并且由于两个语句的类型不同,我尝试通过传递两个选择来进行第一个测试,但我无法做到。

我的代码

Connection connection = null;
    
try {
    // Create the connection
    Class.forName(driver);
    connection = DriverManager.getConnection(url,username,password);
    if(connection != null){
        System.out.println("Connection Established");
    }
    else {
        System.out.println("Connection Failed");
    }
    // create the statement
    //Statement statement = connection.createStatement();
    StringBuffer sql = new StringBuffer( "select 1;" );
    sql.append( " select 2" );
    CallableStatement stmt = connection.prepareCall(sql.toString());
    boolean results = stmt.execute();
    while ( results ) {
        ResultSet rs = stmt.getResultSet();
        try {
            while (rs.next()) {
                // read the data
            }
        } finally {
            try { rs.close(); } catch (Throwable ignore) {}
        }
    }
}
catch (Exception e) {
    System.out.println(e.toString());
}
connection.close();

我得到的错误

[Simba]SparkJDBCDriver 错误处理查询/语句。错误代码:0,sql 状态:运行查询时出错:org.apache.spark.sql.catalyst.parser.ParseException: 外来输入 'select' 期望 {,';'}(line 1,pos 10)

我已经尝试过使用 PreparedStatement 类或仅使用 Statement 而不是 CallableStatement,但我遇到了同样的错误

将选项 allowMultiQueries 添加到连接字符串也没有任何区别,但我相信问题在于它可以采取行动之前。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...