I can enter data into my table using the traditional executeUpdate() method. So I know I'm not completely crazy. But I want to get with the modern world. I'm trying to use a ResultSet to enter data but I keep getting an error. Here's my code: ==============================================
================================================= I've double checked the data types. They are fine. The error is thrown when it reaches rsTask.insertRow(). I get the following error. (printStackTrace) java.lang.ArrayIndexOutOfBoundsException: 1 void sun.jdbc.odbc.JdbcOdbcResultSet.bindCol(int, int) JdbcOdbcResultSet.java:4506 void sun.jdbc.odbc.JdbcOdbcResultSet.insertRow() JdbcOdbcResultSet.java:3962 void mytagtest.NewTask.doPut(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) NewTask.java:107 void .....and so on. As far as I can see, I am doing just like it is recommended in the tutorial. What do you think is the problem?
Hmmm... that's the first I have ever heard that executeUpdate is outdated? A couple things... 1. If your only intent in your code block is to insert a new row then I would not recommend the overhead of actually running the query as what happens with .executeQuery() if you are not going to process the rs. I would use executeUpdate() or do it as a PreparedStatement instead. 2. Not sure if this is true with all dbs but ours (Informix) requires that the table have "rowids" in order to use an updatable rs. The "rowid" is a hidden column that the db uses to uniquely identify a row (like a serial field you don't normally see). Hope that helps.
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Joined: Jul 18, 2002
Well, maybe it's not the modern world. I'm just hacking around trying to find something that looks clean and works. This updatable ResultSet looked interesting because you didn't have to concatenate some ugly SQL. I also cut my teeth on MS Access, and it looked like the ol' DAO stuff. A bit familiar. And, yes, since I'm hacking around, I'm using an Access db. Eventually I'll use Oracle. I also have an autonumber field in the table that creates a unique number for each record. And I made sure I have a recent ODBC driver. But isn't it interesting I get an out of bounds array exception. It has to be something to do with java.sql.'something'. I have no array in my code. I was wondering if anyone had run into this. Is it a bug? Did I not intone the proper mystic words? Maybe this is a feature that will work one day...but not now. Anyone else seen this?
just a note: Scrollable resultsets may give you more headaches than they are worth. Scrollable resultsets are slower, use more memory, and do not work well when using odbc drivers. They also tend to be a database resource hog. But I'll give you that they look nice! Jamie
Joined: Sep 13, 2002
I was able to duplicate your error. I also tried it on our Informix db and I got a NullPointerException instead. In both cases, it's the jdbc driver that's throwing the exception - somewhere in the driver's code, it's using an array. It sounds to me like it is a feature not fully implemented in the jdbc-odbc bridge driver. If you're looking for cleaner code, I really suggest a PreparedStatement, especially if you are executing the same insert multiple times...
Joined: Jul 18, 2002
Thanks, everyone, for your help. And Blake, thank you for going to the trouble of reporducing my error. I may be crazy, but I'm not crazy about this, at least.
"turncom", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements. Thanks. Dave