Entering data from JTextfield into Database Techniques
hello friends,
I am developing an application where i want to insert data from my Jtextfield to data base.
I know all the procedure but i am confused.
I have 11 fields in my frame, out of which 3 are compulsory. rest are optional.
i am validating those 3 compulsory fields.
so i have to generate run time insert query, depending on the fields Populated.
Also i have my connection to db in other class. that not a problem as i can call a method. But how to pass so many arguments. when no. of arguments also change runtime.
[566 byte] By [
Avinash.Ka] at [2007-11-27 7:37:52]

# 1
you need to create a
[url=http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example
Program[/url] (SSCCE) that demonstrates the incorrect behaviour.
Don't forget to use the [url=http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url]
so the posted code retains its original formatting.
# 2
Thanks Aniruddha,
But i didn't understand what u said.
I think I will do as following
1. check the populated field.
2. if yes then insert them into a hashmap .
key = field name, value = field value
3. send the hash map as the argument to function connecting my db.
4. retrieve the fields. and dependingly make a prepared statement for insertion.
5. as some of my fields are integer, convert them to int . then set them
6. then execute the query.
if u have any other suggestions please tell....
# 3
hi
why do you keep in hashmap, just create a class that will have those fields as member variables, and with getter - setter. now the place where you were populating the hashmap, just create this object, and instead of hashmap, pass this object, this way it can be integrated with hibernate as well in future. the class is then your pojo of that table.
regards
Aniruddha