File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update to database problem

 
Bob Young
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can you try this
replace

to

-------------
Sainudheen
[ September 29, 2003: Message edited by: Sainudheen Mydeen ]
 
Bob Young
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
-----------------
Sainudheen
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic