• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert statement by adding variable

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys.. Its good to go..
Cheers
Jowsaki
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic