Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes using variables or input GUI components in SQL insert statement as arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "using variables or input GUI components in SQL insert statement as arguments" Watch "using variables or input GUI components in SQL insert statement as arguments" New topic
Author

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

rameshmca rk
Greenhorn

Joined: Jan 27, 2007
Posts: 17
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

Joined: Dec 06, 2005
Posts: 1321

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..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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..
 
GeeCON Prague 2014
 
subject: using variables or input GUI components in SQL insert statement as arguments