aspose file tools
The moose likes JDBC and the fly likes Insert statement by adding variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Insert statement by adding variable" Watch "Insert statement by adding variable" New topic
Author

Insert statement by adding variable

Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi All,
My requirement is that I have a variable like
title = "Hello world"
and my insert statement is like
insertSQL = "INSERT INTO TblCategory (CategoryKey, Title, ContentTypeKey) ";
insertSQL += " VALUES(" + key + ", " + title + "," + contTypeKey + ")";
when I was trying to insert in oracle the title varible is expecting ''.
Please help me out... how can I resolve it.
thanks
Regards
Sham
SQL: INSERT INTO TblCategory (CategoryKey, Title, ContentTypeKey) VALUES(19, Helloworld,2)
Jack Daniel
Ranch Hand

Joined: Jun 15, 2002
Posts: 163
Hey sham..
I guess Title is of VARCHAR type.. in your table definition..
Then it should be :
insertSQL += " VALUES(" + key + ", " +"'"+title +"'"+"," + contTypeKey + ")";
hope this helps..
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
If you don't want to worry about these types of issues then you should switch to PreparedStatements and let the JDBC Driver handle them. You would then get the additional performance benefit of precompiled statements.
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Thanks Guys.. Its good to go..
Cheers
Jowsaki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert statement by adding variable
 
Similar Threads
mysql help
Error in insert into
Auto Increment ID Field Table in the Oracle Database
Java/ SQL-Server- What is wrong with my INSERT?
Weird number been put to DB table through JDBC