PreparedStatement preparedStatement = connection .prepareStatement("select * from account where account_no = ‘#{account_no}‘;"); preparedStatement.setString(1, "" + account_no); ResultSet resultSet = preparedStatement.executeQuery(); String x = null; while (resultSet.next()) { boolean next = resultSet.next(); double aDouble = resultSet.getDouble(1); double freezed_amount = resultSet.getDouble(2); x = aDouble + " -- " + freezed_amount; System.out.println(x); }
java.sql.PreparedStatement void setString(int parameterIndex, String x) throws SQLException Sets the designated parameter to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument‘s size relative to the driver‘s limits on VARCHAR values) when it sends it to the database. Params: parameterIndex – the first parameter is 1, the second is 2, ... x – the parameter value Throws: SQLException – if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs or this method is called on a closed PreparedStatement
java.sql.SQLException Parameter index out of range (0 1 ).
原文:https://www.cnblogs.com/FlyAway2013/p/14305312.html