• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

To insert value from text field into MySQL database

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's better to ask questions about JDBC in our JDBC forum. So I will move this post there.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic