简体   繁体   中英

MySQL Result Set - No value specified for parameter 1

I can't figure out what this error means or how to fix it. I'm trying to retrieve some data from one of my databases but keep running into this error message below.

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)

It is maybe because you didn't set parameter for your request:

SELECT * FROM mydatabase WHERE TickerID= ?

You have to add:

preparedStatement.setString(1, "youUserIdValue");

Before to execute the query.

You can also use named parameter:

preparedStatement = connect
        .prepareStatement("SELECT * FROM mydatabase "
                    + " WHERE TickerID=:userID");
preparedStatement.setString("userID", "youUserIdValue");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM