Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using variables or input GUI components in SQL insert statement as arguments

 
rameshmca rk
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I had an error as "unclosed string literal" when i tried to give &textbox.getText()& as an input for a insert statement as follows

Connection con=DriverManager.getConnection("jdbcdbc:AllSql");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into Login
values(&text1.getText()&,&text2.getText()&");

help me to insert values through input GUI Components to database tables.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to you use PreparedStatement it is more better solution then statement for insert query..

PreparedStatement JavaDoc

or you would find more example of PreparedStatement on google..
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rameshmca rk:
stmt.executeUpdate("insert into Login values(&text1.getText()&,&text2.getText()&");


unclosed string literal: error is occured because you didn't follow the right way to defining a variable inside your query..

for example..


hope it helps..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic