File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL query" Watch "SQL query" New topic
Author

SQL query

Rahul Surati
Greenhorn

Joined: Mar 04, 2009
Posts: 20
hello i am getting error in the following code..
"INSERT into test VALUES("+jTextField1+","+jPasswordField1+")";
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
Hi Rahul,

some more details would be nice (e.g. which error do you get), but I suppose there are some quotation marks missing..

I think it should look like this:

"INSERT into test VALUES('"+jTextField1+"','"+jPasswordField1+"')";


John
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2499
    
    8

And it might help if you mention the column names between test and VALUES.
like: insert into table (column1, column2) values (value1, value2)

And, as John pointed out, we can be of little help when we don't know the error message.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Or better yet:
"INSERT into test VALUES(?, ?)"

A prepared statement should be used here so there can't be a SQL injection attack using the password field.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Rahul Surati wrote:hello i am getting error in the following code..
"INSERT into test VALUES("+jTextField1+","+jPasswordField1+")";


irrespective of this use..prepared statement.........otherewise for different password ,parser have to again and again prepared for execution plan..............

[jc: fixed quotation marks]


SCJP6.0,My blog Ranchers from Delhi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL query