• 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

dealing with ' -- an apostrophe

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic