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

标签 java hbase apache-phoenix

我正在使用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/

相关文章:

Java 模数和除法

scala - 使用谓词下推连接两个数据集

hadoop - 在 hadoop 多集群中更改 ssh 默认端口

mysql - 尝试链接 phoenix 和 MySQl compile.gettext 错误

java - HstSiteConfigurer : ComponentManager initialization failed

java - 为什么在传递给 XPathExpression.evaluate 方法时不需要转换 Document 对象?

Java:基于对象值的同步

hbase - 如何获取mapr-db表的大小?

hbase - 凤凰;如何使用案例创建 View

hadoop - org.apache.hadoop.hbase.TableNotFoundException : SYSTEM. 目录异常与凤凰 4.5.2