I have a JSP that displays a table that is created by SQL Queries. At the end of each row I included a column that contains check boxes. Because the data in the table is constantly changing I need the value of that check box to be changing with it. So in my JSP I used an EL expression that dynamically generates the value of the value field and set it to the primary key field of the database it is querying.
Here is my JSP code that I was mentioning:
*That is just the relevant portion of it.
I know that this works (i.e. it makes each value of the value attribute equal to the primary key field (Ref_Num)). But how do I pass this value to a servlet so it can update the database?
Here is my servlet code:
*again just the relevant portion
When I run this I get a Null Pointer Exception.
Any help would be greatly appreciated. I can include the rest of the code if need be.
To check and see if the values were even being passed to it. And in my console this is what I was getting:
Database was updated (the 2 values I passed to it were 1.0 and 2.0. So it is getting the values and that is apparently the correct code for that.
But when I put the query and statement code back in (changed from a Statement to a PreparedStatement) I get this error:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
Can I not pass the value of an array as part of an SQL Statement?
Thank you for the suggestion. I changed the code and moved the PreparedStatement command to the correct spot so that more then one check box can be checked at one time.
Could you divulge on what you mean by this:
I'd also suggest using a PreparedStatement in the way it was supposed to be used. Here's a fragment of code which shows the general idea:
view plaincopy to clipboardprint?
String query = "UPDATE Objectives"
+ " SET Objectives.Completed=True"
+ " WHERE Objectives.Ref_Num = ?";
PreparedStatement stmt = conn.prepareStatement(query);
I went to the API and I saw what setString did, but executeUpdate is also mentioned in there. And since I want to update the database, why would I want to do setString.
I am reasonably new to programming so I am still learning a lot of this stuff.
Chris Whited wrote:I went to the API and I saw what setString did, but executeUpdate is also mentioned in there. And since I want to update the database, why would I want to do setString.
Here's a tip: the API is a useful tool if you want to know what a method does, but it isn't a useful tool if you want to know why to use a method. For that you should be reading a tutorial. In general if you want to find a tutorial about Java feature X, your web search keywords are "java X tutorial".