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 Swing / AWT / SWT and the fly likes To insert value from text field into MySQL database 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 » Swing / AWT / SWT
Bookmark "To insert value from text field into MySQL database" Watch "To insert value from text field into MySQL database" New topic
Author

To insert value from text field into MySQL database

maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
Hello!

I am trying to insert a value that user inputs from applet's text field into MySQL database. The connection is made and it does input when I put some string in, but I have to call the variable which contains the inputted string from text field.

I'm having one more problem: when I input string the database inputs many rows with the same content in that field where I inputted string and only ID changes. I'm working in NetBeans.

Here is my action method where I defined the action with text field (plaintext is my textfield and plaintextvalue is the label which displays inputed value in text field on applet...):



Here is my code where I wrote the INSERT statement:



A couple of minutes of your time could save me hours. Please help.

Greetings!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's better to ask questions about JDBC in our JDBC forum. So I will move this post there.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

From a JDBC perspective, you want to use a PreparedStatement so you can call ps.setString(1, text). Otherwise you have to worry about escaping the string and SQL injection.

I'm going to moving this (back?) to Swing where someone can tell you how to get data from a textbox.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
maja neskovic
Ranch Hand

Joined: Apr 28, 2010
Posts: 134
Hello, friends

I have succeed to insert the text in MySQL database. Here is the explanation for all with this problem:

It was a silly mistake because I put the INSERT statement otuside the action method (I put it in render method ). It has to be in action method next to the action related to confirm button click.

Thank you all for interesting in my problem

Greetings!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To insert value from text field into MySQL database
 
Similar Threads
Only for one data in the text box
Insert VALUE from JTEXTFIELD to DATABASE
exception
Edit nested input element value attribute
Enabled Web start in NetBeans, but lost database connection