我无法弄清楚此错误的含义或解决方法。我试图从我的一个数据库中检索一些数据,但仍然遇到以下错误信息。
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)
答案 0 :(得分:7)
您需要填写PreparedStatement
preparedStatement.setLong(1, someIdentifier)
答案 1 :(得分:2)
可能是因为您没有为您的请求设置参数:
SELECT * FROM mydatabase WHERE TickerID= ?
你必须添加:
preparedStatement.setString(1, "youUserIdValue");
在执行查询之前。
您还可以使用命名参数:
preparedStatement = connect
.prepareStatement("SELECT * FROM mydatabase "
+ " WHERE TickerID=:userID");
preparedStatement.setString("userID", "youUserIdValue");