hi all, Please tell me the best practice for store my form data persistently in my database.
I have one form for to track the user input i.e first name,last name and email id.when user fill and submit it will go for validation ,if entries are fine it goes to servelet,in that servlet i instantiate the bean and using setter methods of the bean i am storing the data temporarily upto now.
now my request is i want to store the form data in our database which is oracle8i, and if i want to retrieve later it is also recommended.so for this scenario how to write the code and where i need to write the code .writing the code in servlet is better or in separate bean.so which one is good and if possible give me sample code for better understanding.
Entity beans/session beans will be best if you are using EJBs..
If you are using JDBC, try to design some generic classes which can be reused.. you can have java beans or value objects for holding table data. put all your queries into xml file so that db changes doesn't affect your code.. Have a seperate class to do all db operations..
Also, JavaRanch is not a code mill. People here are happy to help you if you get stuck on something specific when working on your project but nobody here is going to hand you back a solution if all you can give us are your requirements.
What have you done so far? What part are you stuck on? [ January 20, 2006: Message edited by: Ben Souther ]
I recommend you read into JDBC usage or an ORM framework like Hibernate. I personally prefer Hibernate as it leads to more structured and easily modifiable code. It is also database independent and that is quite a plus.
If so, you could start by either, making that javaBean database capable (add methods that read and write to the database) or by creating another object who's job it is to read and write the fields from that bean to/from the database. Either way, start out by giving your objects main methods so you can perform the database operations from the command line. Don't even try to work with these beans from the servlet app until you know the database methods work.
For the sake of simplicity, I would start out by loading the driver from within your database method using forName(drivername). Once it's working and you're comforatable with that, I would look into the connection pooling mechanism provided by your servlet container.
If you're not familiar with JDBC, there are plenty of tutorials
Joined: Nov 28, 2005
hi ben, thanks for your advice.
Are you familiar with JDBC?
yes, i am familiar with JDBC.but only the problem is how and where i need to write the code to store the form data in database.please see the code in above reply.I loaded the oracle thin driver ,it is working fine.please initiate me to write the relevant code for to store the data in database. The important point is 1.where i need to write the code 2.please give me code sample for to write my appliation specific code,plese see the code i posted above.