• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To insert value from text field into MySQL database

 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20725
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's better to ask questions about JDBC in our JDBC forum. So I will move this post there.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
maja neskovic
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic