File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dealing with ' -- an apostrophe

 
Sam Kebab
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems inserting some rows that include ' -- i.e. an apostrophe.
For instance M'PLX-W.
My program inserts around 5 to 10 thousand rows a night. I can't manually put an escape character. Would anyone know how i can handle this. For this program i will be using MS SQL database.
ps. I tried using prepared Statements -- and they seem to work fine; but much to my dismay prepared statements are (literally) running 20 times slower than the regular create statement.
 
Adam Hardy
Ranch Hand
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why your prepared statements are running slower, someone else will have to answer that.
But you didn't say what the problem with the apostrophes actually is. Presumably they're causing your SQL statements to break? Or is it your HTML/Javascript that they're breaking? You have to escape them or substitute them.
Adam
 
Richard Whitely
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like u are preparing the statment every time u use it, prepare it once then use it many times to see the performance improvment over a statment.
 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if its a form then when you get the data in the next page .. call a bean which modified the string by adding an escape character before the '
call the bean , set the string , call the modify function and then get the string by the getter method.
use any string manipulation method like StringBuffer etc...
i did the same .. then pass the modified string for insertion in the database...
let me know if it works for you
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you can do a few things to improve performance:
1. declare the PreparedStatement outside the loop to insert 10000 rows
2. Batch the preparedstatements
example:

batching your statements will give you a huge performance gain. PreparedStatements when utilized properly will give you performance gains on repeated execution of the same statements.
Give it a try and see what happens, or maybe post some relevant code (if there is a lot, then skeleton it for us!)
Jamie
 
Sam Kebab
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help -- everyone.
I can't wait to try out your advice -- on Monday. I have a strong feeling it will work.
 
Sam Kebab
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jamie.
Wow!!! The batch update has made the program loop "faster than a speeding bullet". (although i used the regular create statement).
I have one small problem though when using the batch update with a prepared statement -- the error reads:
invalid transaction state
java.lang.NegativeArraySizeException
-- i think the line: int [] inserts = ps.execut..
reads - (negative).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic