This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes database best practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "database best practice" Watch "database best practice" New topic
Author

database best practice

A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
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.

thanks all in advance.

cheers,
babu.
[ January 19, 2006: Message edited by: Bear Bibeault ]

Thanks,
www.Admakr.in
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi all,
please extend the thread.

cheers,
babu.
Rajasekar Elango
Ranch Hand

Joined: Sep 13, 2004
Posts: 105
here is some suggestions..

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..

Have a look at DAO pattern..

Regards,
Raja.


SCJP 1.4
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi raj,
i am using only jdbc and i am willing to use normal javabean for to hold table data.please give any code sample for to achive it.

cheers,
babu.
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hello all,
please extend the thread.please.

cheers,
babu.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by babu amara:
hello all,
please extend the thread.please.

cheers,
babu.


Babu,
Please read this:
http://faq.javaranch.com/view?PatienceIsAVirtue

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
below is my view.jsp:
========================


below is my servlet:
====================


below is my bean:
==================

upto now i am keeping the data in bean for short period,now i want that form data in database.how i can achive.
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you familiar with JDBC?

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
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
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.


thank s in advance.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Babu",
You have 62 posts and an invalid display name. If you do not correct your display name your account will be closed.

We require display names to be two words: your first name, a space, then your last name. Fictitious anme are not allowed.

Please correct your display name immediately.

thanks,
Dave.
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi all,

sorry single word name.I changed to two word name.

thanks .
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi all,

thank s i got solution to store the form data in database.
thanks wonderful javaranchers.

cheers,
babu.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database best practice
 
Similar Threads
confused between attributes and parameters
Need to know best approch to store a photo/video/audio/pdf in j2ee application
Need to know best approch to store a photo/video/audio/pdf in j2ee application
regarding the jsp data store
how to store data