MySQL 结果集 - 没有为参数 1 指定值
MySQL Result Set - No value specified for parameter 1
我不知道这个错误是什么意思或如何修复它。我正在尝试从我的一个数据库中检索一些数据,但一直遇到下面的错误消息。
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)
可能是因为您没有为您的请求设置参数:
SELECT * FROM mydatabase WHERE TickerID= ?
您必须添加:
preparedStatement.setString(1, "youUserIdValue");
在执行查询之前。
您还可以使用命名参数:
preparedStatement = connect
.prepareStatement("SELECT * FROM mydatabase "
+ " WHERE TickerID=:userID");
preparedStatement.setString("userID", "youUserIdValue");
我不知道这个错误是什么意思或如何修复它。我正在尝试从我的一个数据库中检索一些数据,但一直遇到下面的错误消息。
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)
可能是因为您没有为您的请求设置参数:
SELECT * FROM mydatabase WHERE TickerID= ?
您必须添加:
preparedStatement.setString(1, "youUserIdValue");
在执行查询之前。
您还可以使用命名参数:
preparedStatement = connect
.prepareStatement("SELECT * FROM mydatabase "
+ " WHERE TickerID=:userID");
preparedStatement.setString("userID", "youUserIdValue");