- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对 ResultSet 进行更新,但出现异常,No primary key found for table nvp,
on a table that has a primary key.
它是 PostgreSQL 9.6.1.0,jdbc 驱动程序版本是从他们的网站下载的 postgresql-9.4.1212.jar(JDBC42 Postgresql 驱动程序,版本 9.4.1212 来自 here)。
@Test
public void testUpdateableResultSet() throws Exception {
String url = "jdbc:postgresql://localhost:5432/dot";
Properties props = new Properties();
props.setProperty("user", "dot_test");
props.setProperty("password", "test_dot");
props.setProperty("currentSchema", "dot_test");
try(Connection conn = DriverManager.getConnection(url, props)) {
conn.setAutoCommit(false);
try(Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
s.execute("drop table if exists nvp");
s.execute("create table nvp (id int primary key, value text);");
s.execute("insert into nvp (id, value) values (1, 'one_'), (2, 'two_')");
}
try(PreparedStatement ps = conn.prepareStatement("select value from nvp",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = ps.executeQuery()) {
while(rs.next()) {
String s = rs.getString(1);
if(s.endsWith("_")) {
s = s.replace("_", "");
}
else {
s = s + "_";
}
rs.updateString(1, s); // line 28
System.out.println("row updated");
}
}
}
}
结果如下。
Testcase: testUpdateableResultSet(com.tekbot.lib.sql.SimpleTest): Caused an ERROR
No primary key found for table nvp.
org.postgresql.util.PSQLException: No primary key found for table nvp.
at org.postgresql.jdbc.PgResultSet.isUpdateable(PgResultSet.java:1586)
at org.postgresql.jdbc.PgResultSet.checkUpdateable(PgResultSet.java:2722)
at org.postgresql.jdbc.PgResultSet.updateValue(PgResultSet.java:3056)
at org.postgresql.jdbc.PgResultSet.updateString(PgResultSet.java:1393)
at com.tekbot.lib.sql.SimpleTest.testUpdateableResultSet(SimpleTest.java:28)
这是一个错误吗?我错过了一步吗?
最佳答案
The primary key must be specified so that the result set is updateable
将您在第 17 行
上的查询更改为:
PreparedStatement ps = conn.prepareStatement("select id, value from nvp"...
关于java - PostgreSQL 错误更新表上的 ResultSet "No primary key found for table"w/key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41052361/
在我的应用程序中,我必须获取记录并将它们放入二维数组中。我必须首先触发两个查询以找出计数,以便我可以初始化数组,其次是获取数据。它会导致性能下降。我需要提高性能的解决方案。 谢谢。 最佳答案 I ha
在 Zend Framework 应用程序中,它的构建与 ZF2 Getting Started tutorial 中的相册应用程序非常相似,我使用 ResultSet 对象将数据从模型通过 Cont
我是 java 和 SQL 新手,我重复了一个我不知道如何避免的问题: 假设我想创建两个executeQuery,一个在另一个内部,在getRequestsFromDB方法中我创建第一个execute
这个问题已经有答案了: Why should I call close() on a ResultSet and Connection instance? (4 个回答) 已关闭 7 年前。 使用完结
public List searchCourse(String name) { List list = null; Course course = null;
我正在使用两个不同的查询从两个表中选择数据。我正在使用一个连接和一个结果集。两个表都已填充,但第二个查询的 resultset.next() 返回 false,尽管它必须为 true。 我还尝试使用两
试图了解这里发生了什么。 DatabaseMetaData 返回一个空结果集,而实际上相同的 SQL 查询则不会。这不是主要问题,因为我使用第二个代码示例作为解决方法。 DatabaseMetaDat
假设我有多个结果集(每个结果集将引用数据库中的 1 行)(它们属于同一个表。)。现在我想创建合并的结果集,它将实习生拥有所有其他结果集。所以我的主要目标是创建一个组合的 ResultSet,它将指向以
我正在尝试将 influxdb 与我的应用程序集成并处理输出。我正在导入 InfluxDBClient 包以连接到在我的本地计算机上运行的 influx 实例。使用以“influxdb.results
我正在尝试创建一个框架来显示数据库中的所有电影名称,然后他们选择框架中的一行来执行另一个查询。 我有一个 ResultSet (rs),它接收查询执行的结果以选择电影名称。之后,我使用 SQLTabl
我有一个 Servlet,它使用返回 ResultSet 的静态实用程序方法。 在我的 Servlet 代码中,我有 ResultSet rs = SimpleSearch.searchByName(
在从 Postgres 或 Oracle 检索时间戳时(我们称之为 startDate),使用 resultSet.getString("startDate") 调用或 resultSet.getTi
全部, 对于名为Analyze 的类及其构造函数Analyze,该构造函数将Java JDBC Resultset 对象作为参数。 private Resultset analysisSet publ
m 尝试遍历 3 个结果集并比较它们的值。 bt 它抛出这个异常......有人可以帮助我了解我正在经历的地方吗?这是一段代码: java.lang.Object[] reconciledPaymen
我已经尝试使用谷歌搜索并在 SO 上查看了这些线程: java jdbc accessing multiple resultsets Open two resultsets simultaneousl
我在 SQLite 的 JDBC 驱动程序中遇到问题。 我正在使用 SELECT 语句执行查询。 如果我得到一个空的 ResultSet(0 行),那么我会在调用 getString(1) 时看到抛出
我正在尝试根据特定条件搜索表格。在 SQL Developer 中执行时,SQL 查询返回正确的结果(1 行)。在 JDBC 中,resultset 不为 null,但 resultset.next(
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我正在尝试在 Java 应用程序中处理大量数据。数据存储在 MySQL 数据库中,我使用的是 jdbc 连接器 8.0.11。 我的问题是我需要多次访问每条记录并且再次执行查询需要太多时间。使用 Re
这个问题已经有答案了: Getting java.sql.SQLException: Operation not allowed after ResultSet closed (2 个回答) 已关闭
我是一名优秀的程序员,十分优秀!