Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能';t使用PostgreSQL JDBC驱动程序获取GetGeneratedKey_Postgresql_Jdbc_Resultset - Fatal编程技术网

我能';t使用PostgreSQL JDBC驱动程序获取GetGeneratedKey

我能';t使用PostgreSQL JDBC驱动程序获取GetGeneratedKey,postgresql,jdbc,resultset,Postgresql,Jdbc,Resultset,我在一个函数中遇到了一个愚蠢的问题。 我想获取一个Sql查询的generatedKey。我不能也不明白为什么。问题是resultSet.next()即使在检查表中的数据时插入了行,它也会返回false 这是我的密码: Statement statement = connection.createStatement(); statement.executeUpdate("INSERT INTO calamar.calamar.application (nom,criticite,autorise)

我在一个函数中遇到了一个愚蠢的问题。 我想获取一个Sql查询的generatedKey。我不能也不明白为什么。问题是
resultSet.next()
即使在检查表中的数据时插入了行,它也会返回false

这是我的密码:

Statement statement = connection.createStatement();
statement.executeUpdate("INSERT INTO calamar.calamar.application (nom,criticite,autorise) VALUES ('"+nom+"','"+criticite+"','"+false+"');");

 ResultSet resultSet = statement.getGeneratedKeys();
 resultSet.next();

解决方案:添加
语句。返回\u生成的\u键

Statement statement = connection.createStatement();
statement.executeUpdate("INSERT INTO calamar.calamar.application (nom,criticite,autorise) VALUES ('"+nom+"','"+criticite+"','"+false+"');", Statement.RETURN_GENERATED_KEYS);

ResultSet resultSet = statement.getGeneratedKeys();
resultSet.next();

尝试添加
语句。返回\u生成的\u键作为
.executeUpdate
方法调用的第二个参数(在SQL语句之后)。哦,天哪。。。它成功了,非常感谢!你应该把你的解决方案作为一个答案发布,甚至接受它。我很惊讶这是可行的<代码>插入calamar.calamar.application
对于Postgres无效,因为您不能在那里有一个由三部分组成的标识符。你确定你在使用Postgres吗?另外:请使用
PreparedStatement
代替可能的副本