【发布时间】:2018-03-19 23:47:23
【问题描述】:
需要你的帮助!
我正在尝试使用驱动程序类 (com.simba.cloudspanner.core.jdbc42.CloudSpanner42Driver) 执行 DML 操作,但我遇到了类似
的异常"Caused by: shaded.com.google.cloud.spanner.SpannerException: INVALID_ARGUMENT: DML statements(INSERT, UPDATE and DELETE) are not supported."
但 SELECT 查询工作正常。下面是我的java代码。
请告诉我如何从 java 应用程序对 spanner 执行 DML 操作。
我尝试使用Mutation.newInsertBuilder、Mutation.newUpdateBuilder、Mutation.delete 来实现使用com.google.cloud.spanner.Mutation; libraries 的 DML 操作,但是我实际上正在寻找某种实现,用户可以运行 SQL 语句来执行DML 操作。
public class SimbuDriverInsert {
static final String CONNECTION_URL = "jdbc:cloudspanner://localhost;Project=optimistic-leaf-197820;Instance=testspanner01;Database=students;PvtKeyPath=C:\\MuleWorkspace\\test-driver\\src\\main\\resources\\gcloudPrivateKey.json";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.simba.cloudspanner.core.jdbc42.CloudSpanner42Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(CONNECTION_URL);
stmt = conn.createStatement();
String sql = "INSERT INTO studentdetails (id,age,name) " +
"VALUES (100, 30, 'Ali')";
stmt.executeUpdate(sql);
System.out.println("Inserted record into the table...");
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}
}//end main
}
【问题讨论】:
标签: google-cloud-platform google-cloud-spanner