• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Insert statement by adding variable

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys.. Its good to go..
Cheers
Jowsaki
 
reply
    Bookmark Topic Watch Topic
  • New Topic