Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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("jdbc:odbc: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: 1325
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: 1325
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..
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!