This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting | into oracle DB

 
steph rinert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am inserting some values into an oracle DB and the following error does not allow me to insert the data ***java.sql.SQLException: ORA-00996: the concatenate operator is ||, not |***
The data that i am inserting does contain numerous single | (pipes) and i am using a generic "insert into (table) values (" + vector (contains many columns) + ")";

Thank you
 
steph rinert
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and I believe the problem is that my data is not wrapped with single quotes since its in a vector, if so, then how would i wrap each column in single quoutes in the vector before I use it in the insert statement.
Thanks
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of trying to build a single SQL statement into a String, it is better to use a prepared statement. That way, you don't have to worry about special characters such as | and '

This will work as long as the String returned by myVector.toString() is short enough to fit into the database column.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Michael
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Michael,
Can I use a BLOB field in a prepared statement ?
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by achana chan:
Dear Michael,
Can I use a BLOB field in a prepared statement ?

Probably. But it might not be as easy as you think. A Blob must first be fetched from the database. Then you can fill it with byte[] s, and set it back.
It depends on your database driver and database.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic