gpt4 book ai didi

java - 无法使用PreparedStatement在Phoenix中插入行

转载 作者:行者123 更新时间:2023-11-30 06:26:06 25 4
gpt4 key购买 nike

我正在使用phoenix-4.7.0-HBase-1.1-bin。我尝试使用 PreparedStatement API 将一行插入数据库,但没有插入任何行,也没有抛出异常。这是我的示例程序:

    import java.sql.*;

public class PhoenixExample {
public static void main(String[] args) {
try {
// create a mysql database connection
String myDriver = "org.apache.phoenix.jdbc.PhoenixDriver";
String myUrl = "jdbc:phoenix:host:2181:/hbase";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "", "");

String query = "UPSERT INTO floattest(value1, value2) values(?, ?)";

// create the mysql insert preparedstatement
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setFloat(1, 1094993918);
preparedStmt.setFloat(2,804081421);

// execute the preparedstatement
boolean executed = preparedStmt.execute();
System.out.println("EXECUTED = " + executed);
preparedStmt.close();

conn.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println("Got an exception!" + e);
System.err.println(e.getMessage());
}
}
}

我在准备声明时遗漏了什么吗?我应该如何修改它才能成功插入一行?

最佳答案

执行准备好的语句后必须调用 Commit。一般自动提交设置为10000行。尝试commit preparedStatement执行

ps.executeUpdate();

conn.commit();

关于java - 无法使用PreparedStatement在Phoenix中插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47181805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com