• 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

concatenating the values before inserting

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,,
I got the following problem. Tried several alternatives but most of the times in vain!!
I will be inserting the following.

" INSERT INTO TEMPLATES(ID, TEMPLATE_CATEGORY, TEMPLATE_NAME, TEMPLATE_FILE_CONTENT) "+" VALUES +"('"+id+"',' "+templateCat+" ','"+templateName+"', EMPTY_BLOB()) ";

I need to concatenate the id, templateCat and templateName and insert that string as value in TEMPLATE_NAME column.

i.e, instead of +templateName+ ...i need the concatenated string.

I tried several possibilities but getting errors. any idea???

regards,
Navi
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This shouldn't be that hard to do, I'm guessing that you're tripping over some minor syntax errors in building your string. The chances of those types of errors drop substantially if you use PreparedStatement instead of Statement; you break the problem up from building one complex dynamic String into writing one essentially static SQL statement, and then building each value correctly.

Assuming that ID is numeric and the other things are String:

If id is a String, just change the set method above...
 
navi kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , tnx for the reply.

yes I am using Prepared Statement. Also the id is a varchar and not numeric.
Basically, i am inserting a blob, for that I will get the output stream from the Blob to insert it. i will select the blob and update with the dummy value.

For this reason, I will not be writing any setString or setInt just after the initial insert statement!!
 
navi kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or can we do it like this:
" INSERT INTO TEMPLATES(ID, TEMPLATE_CATEGORY, TEMPLATE_NAME, TEMPLATE_FILE_CONTENT) "+" VALUES +"('"+id+"',' "+templateCat+" ','"+id+templateCat+templateName+"', EMPTY_BLOB()) ";
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by navi kumar:
Hi , tnx for the reply.

yes I am using Prepared Statement. Also the id is a varchar and not numeric.
Basically, i am inserting a blob, for that I will get the output stream from the Blob to insert it. i will select the blob and update with the dummy value.

For this reason, I will not be writing any setString or setInt just after the initial insert statement!!



Those are not reasons to avoid setString for the values. Or at least, not reasons that make any sense. The binding (set...) methods have no relationship to your Blob whatsover. The insert isn't executed until after the setStrings... (Preparing isn't executing).
 
reply
    Bookmark Topic Watch Topic
  • New Topic