gpt4 book ai didi

java - SQL异常 : ORA-01008: not all variables bound -- SQL error using java to query database JDBC

转载 作者:行者123 更新时间:2023-11-29 03:22:42 26 4
gpt4 key购买 nike

        Statement stmt = con.createStatement();

String pubBooks = "select title_name " +
"from publisher, title " +
"where pub_name = ? " +
"and publisher.pub_no = title.pub_no " +
"order by title_name";
ResultSet rS = stmt.executeQuery(pubBooks);
stmt.close();
String pubss = "Irwin";
PreparedStatement pStmt =
con.prepareStatement(pubBooks);
pStmt.setString(1, pubss);
pStmt.executeUpdate();

嘿,我正在尝试使用 JDBC 查询我的数据库以获取该出版商制作的书名列表,但是我遇到了错误 java.sql.SQLException: ORA-01008: not all variables bound。我一直在尝试我能想到的一切,但我不太确定此时该做什么。

最佳答案

您接近于尝试 PreparedStatement,只是您调用了错误的“execute”方法。使用 executeQuery() method返回您的 ResultSet

PreparedStatement pStmt = 
con.prepareStatement(pubBooks);
pStmt.setString(1, pubss);
ResultSet rS = pStmt.executeQuery();

关于java - SQL异常 : ORA-01008: not all variables bound -- SQL error using java to query database JDBC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22725395/

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