java - MySQL 结果集 - 没有为参数 1 指定值

标签 java jdbc

我不知道这个错误意味着什么或如何修复它。我正在尝试从我的一个数据库中检索一些数据,但不断遇到下面的错误消息。

preparedStatement = connect
            .prepareStatement("SELECT * FROM mydatabase "
                        + " WHERE TickerID=?");
            resultSet = preparedStatement.executeQuery(); //where it says the error is, line 132
            while(resultSet.next())
            {
                aIDTA = resultSet.getInt("AccountID");
                nameTA = resultSet.getString("Name");
                CashBalance = resultSet.getDouble("CashBalance");
                TradeFeeBuy = resultSet.getDouble("TradeFeeBuy");
                TradeFeeSell = resultSet.getDouble("TradeFeeSell");
                AssetsBalance = resultSet.getDouble("AssetsBalance");
            }



Exception in thread "main" java.sql.SQLException: No value specified for parameter 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
    at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2281)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2261)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2191)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2004)
    at BuyAndSell.BuyAndSell(BuyAndSell.java:132)
    at Main.main(Main.java:21)

最佳答案

您需要在PreparedStatement中填写参数

preparedStatement.setLong(1, someIdentifier)

关于java - MySQL 结果集 - 没有为参数 1 指定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27807726/

相关文章:

java - 我什么时候应该使用连接的 RowSet,什么时候应该使用断开连接?

Java - Lock 如何保证 happens-before 关系?

java - 如何使 Simple 不序列化空 ArrayList?

java - Android中从Json数组解析Json

java - JDBC PreparedStatement导致MySQL语法错误

java - log4jdbc 强制返回 ConnectionSpy 驱动程序

hibernate - 强制 Spring/JPA/Hibernate/JDBC 重试失败的 beginTransaction?

java.lang.ClassNotFoundException : javax. faces.application.ApplicationFactory

java - Wix 嵌入式 mysql 与 spring boot DDL 查询错误对于具有嵌入式 id 的实体

java - 使用 Java 根据条件返回不同类型的对象