aspose file tools*
The moose likes JDBC and the fly likes dealing with ' -- an apostrophe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "dealing with Watch "dealing with New topic
Author

dealing with ' -- an apostrophe

Sam Kebab
Ranch Hand

Joined: Jan 23, 2002
Posts: 104
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

Joined: Oct 09, 2001
Posts: 566
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


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Richard Whitely
Greenhorn

Joined: Feb 08, 2002
Posts: 2
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

Joined: May 08, 2001
Posts: 204
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


regards,<br />Dharmesh Chheda
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jan 23, 2002
Posts: 104
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

Joined: Jan 23, 2002
Posts: 104
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).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: dealing with ' -- an apostrophe