Array Index Out Of Bounds Exception: 0 ( Mistake with My MySQL "count"?)
Joined: Nov 19, 2000
I am using the Tomcat and MySQL. Below is the message in the Tomcat log:
----- Root Cause ----- java.lang.ArrayIndexOutOfBoundsException: 0 at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1845) at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:1056) at org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:217) at org.apache.artimus.message.dao.MySQLMessageDAO.getNumberOfThreadBeans_forReceiver(MySQLMessageDAO.java:514) at org.apache.artimus.message.ListThreadHandler.getNumberOfThreads_forReceiver(ListThreadHandler.java:74) at org.apache.artimus.message.ListThread.execute(ListThread.java:119)
I suppose that the problem is with the method getNumberofThreadBeans_forReceiver (which is line # 514 in the MySQLMessageDAO class). And I also suppose that the "0" caused the ArrayIndexOutOfBoundsException (please point out if I am wrong). However, the method is to "count" the number of records found in the database. And I went to look at my database. I was able to find 3 matches with my eyes.
Please help me to see the mistakes in that method (shown below):
Joined: Mar 18, 2004
No you are not thinking in the right direction. See the code you have written
as you can see you have written String query = "SELECT count(*) FROM message_thread WHERE message_receiver = '" + memberName + "'"; and you are using PreparedStatement. You are setting the message_receiver here in this query and then you are trying to use stmt.setString(1,memberName).There is no ? in the query. So Strange. Isn't it?
Use String query = "SELECT count(*) FROM message_thread WHERE message_receiver = ?"; instead. It will solve the problem. [ May 20, 2004: Message edited by: Ali Gohar ]