I made a method for executing a array of values in Java. Whenever I try to run it, I end up with an ArrayOutOfBoundsException. My console points the error to being the "if" statement.
for (int i = 1; i <= array.length; i++) {
if (array[i] instanceof String) {
ps.setString(i, (String) array[i]);
} else if (array[i] instanceof Integer) {
ps.setInt(i, (int) array[i]);
}
}
I have no problem with the Connection or PreparedStatement from before. I only end up having problems with this method, because of the array(Object[]), is not working correctly. I use this method for inserting and deleting different data from "user" table. I take 4 parameters in here, first being ID(which is auto_generated and put as primary key. Second parameter is the name for my user, third is the users UUID and last one is the rank(kinda accesslevel) for the user. Im expecting that the first one(ID) does not count after it is auto_generated on every insert. So lets not count that with us. Here is a example of how I'm using the method:
executeQuery("INSERT INTO `user` (`name`, `uuid`, `rank`) VALUES (?, ?, ?)", new Object[]{"'username'", "'myUUID'", 64});
So after I have executed this method, I end up with an error telling me this:
java.lang.ArrayIndexOutOfBoundsException: 3
at com.java.tarjeihs.plugin.mysql.MySQLAccessor.executeQuery(MySQLAccessor.java:107) ~[?:?]
at com.java.tarjeihs.plugin.user.UserHandler.test(UserHandler.java:24) ~[?:?]
If you guys had problems understanding my explanation, please ask me for a better explanation.