• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concatenating the values before inserting

 
navi kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic