java - 使用 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' 期望 {,';'}(第 1 行,第 10 行)
我已经尝试使用 PreparedStatement 类或仅使用 Statement 而不是 CallableStatement,但我得到了同样的错误。
将选项 allowMultiQueries 添加到连接字符串也没有任何区别,但我相信问题出在此之前。
解决方案
推荐阅读
- jenkins - 如何从詹金斯工作更新汇合页面
- sql-server - SQL Server 2014 Express 不显示新创建的表
- python - 静态目录文件浏览过早结束
- android - 如何将 onEditorAction 与 Firebase 的 onDataChange 一起使用
- phpmyadmin - cPanel 显示 PHPmyAdmin 以外的其他 PHP 版本
- ios - 创建 git 分支时自动增加内部版本号
- dojo - DOJO 下拉菜单和 datetextbox 在打开/关闭对话框几次后突然停止工作
- perl - 当基础数据被修改时,如何防止引用对象发生变化?
- python - 使用 cython 时出现 GCC 问题
- python - Django 迁移 - django.db.migrations.exceptions.NodeNotFoundError