wood burning stoves 2.0*
The moose likes JDBC and the fly likes update to database problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "update to database problem" Watch "update to database problem" New topic

update to database problem

Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
I could use some help on the following. I am reading up on servlets and JDBC via Java Servlet Programming by Jason Hunter. I have looked at this so long I just can't see my error, but there must be something wrong! I am trying to makeup a simple servlet example using a html form to pick up a parameter from the user and pass it on to the servlet. The servlet should perform an update on the database. When I look at the database nothing is being added. The database is an Access DB and it is hooked up correctly. I can use another app to look at the database and perform a select * from Table1 and see that nothing is added. I am using Tomcat 4.0.1. I have tried doPost and doGet neither worked. I have tried text and int for the parameter. The database is one table called of all things Table1 with the first column SSNum as Number and the next three columns as Parameter1, Parameter2, Parameter3 all as text. Got any ideas? Thanks.

(Marilyn added code tags and disabled smilies)
[ September 29, 2003: Message edited by: Marilyn de Queiroz ]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9044
Your code would be easier to read if you use code tags. Also, I suggest that you decide whether you want to use

and not intermix the two styles.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Can you try this


[ September 29, 2003: Message edited by: Sainudheen Mydeen ]
Bob Young
Ranch Hand

Joined: Dec 23, 2000
Posts: 65
Thanks for replying Sainudheen Mydeen. I was able to get this going by using a preparedstatement, just as you suggested. I know that not all databases are able to use preparedstatement, in particular MySql. I was hoping that somebody could suggest a way to make this work without using a preparedstatement.
However I am about to become bald from pulling out my hair trying to understand this database stuff. Can somebody explain why the following is happening. I am using Access as the database.
This code from a book almost runs but leaves out the last row of data.

The data for insert values 123, name1 and 987, name2 are added to the database but 555, name3 is not! Now I would not mind this happening with my checking account on the debit side, but it would definitely not be good for the credit side. Now if I try much the same code with a servlet, it does not work at all.

Why oh why will this almost work as in the first code example and utterly fail on the second? The only real difference that I see is the servlet
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi Bob Young
I tried to run your program connecting to my Oracle datbase. Both work fine. All three rows inserted. If you are calling your servlet by typing the URL in browser's address bar, change the method name to doGet.
subject: update to database problem
Similar Threads
sql exception : user property is missing ???
insert query not working
MSAccess and JDBC
Formating Date objects
postgres connectivity failure with jdbc