This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to link data input by user into database?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to insert data inserted by user from java swing into table in database ?
I found out many codes are for ourself to insert the data, but how if i want to insert the data inserted by the user ?
         
 
Saloon Keeper
Posts: 5052
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between "insert the data" and "insert the data input by the user"? What difference does where the data comes from to how to insert it into the DB?
 
Nadhirah Zunaidi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What is the difference between "insert the data" and "insert the data input by the user"? What difference does where the data comes from to how to insert it into the DB?



For example,
INSERT INTO people (fname, lname) VALUES" + "('Joe', 'Bloggs'), ('Mary', 'Bloggs'), ('Jill', 'Hill')"

The code above will insert data into the table 'people'.
Okay how if, the data is from a JTextField (which is the data inserted by the user), and how do i code it so that it will be inserted into the 'people' table?  
Sorry for my bad english  
 
Rancher
Posts: 1917
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all use PreparedStatement for sql operations.  Forming a query like this is prone to bugs and vulnerable to sql injections.  Now coming to your question, you can write a method to insert records and to this method you can pass edit field values as parameters.
 
Swastik Dey
Rancher
Posts: 1917
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example of the method that I mentioned can be somewhat like this



and you call the above method from where you wish to save the edit field values.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!