我正面临这个问题:
参数索引超出范围(2>参数个数,即1)
但我无法察觉我错了什么......
关注我的代码:
Constants.java
public static final String INSERTDEVICES = "insert into devices (I_ENVIRONMENT,"
+ "I_APP_ID,E_STATUS,DT_MODIFIED,"
+ "DT_LAST_COMMUNICATION,"
+ "DT_CREATED,DS_ENDPOINT_ARN,"
+ "DS_DEVICE_VERSION,DS_DEVICE_UID,"
+ "DS_DEVICE_TOKEN,DS_DEVICE_NAME,"
+ "DS_DEVICE_MODEL,DS_APP_VERSION,"
+ "B_PUSHSOUND,B_PUSHBADGE,B_PUSHALERT, I_ID_SYSTEM) "
+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
DeviceDAO.java
DBConnect db = DBConnect.getInstance();
try {
Calendar calendar = Calendar.getInstance();
String dName = device.getDeviceName().replace("%20", " ");
PreparedStatement preparedStatement = db.getConnection().prepareStatement(Constants.INSERTDEVICES);
preparedStatement.setLong(1, device.getEnvironment().ordinal());
preparedStatement.setLong(2, device.getAppID().ordinal());
preparedStatement.setString(3, "active");
preparedStatement.setTimestamp(4, new Timestamp(calendar.getTime().getTime()));
preparedStatement.setTimestamp(5, new Timestamp(calendar.getTime().getTime()));
preparedStatement.setTimestamp(6, new Timestamp(calendar.getTime().getTime()));
preparedStatement.setString(7, device.getEndPointArn());
preparedStatement.setString(8, device.getDeviceVersion());
preparedStatement.setString(9, device.getDeviceUID());
preparedStatement.setString(10, device.getDeviceToken());
preparedStatement.setString(11, dName);
preparedStatement.setString(12, device.getDeviceModel());
preparedStatement.setString(13, device.getAppVersion());
preparedStatement.setBoolean(14, device.isPushSound());
preparedStatement.setBoolean(15, device.isPushBadge());
preparedStatement.setBoolean(16, device.isPushAlert());
preparedStatement.setLong(17, device.getSystem().ordinal());
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
此行中引发了异常:
preparedStatement.setLong(2, device.getAppID().ordinal());
枚举: getApID()= Enum EApplication(我们想要使用的应用程序的类型) device.getEnvironment()= Enum EEnvironment(Homologation,Production)
非常感谢!