Inverted Comma database Problem

Hi!

I am using making n article management system

using which i am storing articles in the form of HTML in the database.

& it is working cool i am storing the data in database

but when article have any inverted comma like this

"here's the "preloaded content" "

it gives error in the query execution i am using MySQL

Please Help

BuntyIndia

[407 byte] By [bunty_indiaa] at [2007-10-2 22:12:56]
# 1
It seems that you are concatinating the artical content in to the sql statement as strings.This is not good practice you should be using the PreparedStatements with place holders for data
LRMKa at 2007-7-14 1:29:45 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for reply

can u please provide any example or website where i can get example

I am cocatinating the value in SQL string it stores the data but when i execute it gives this error

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S RFID AUTHORITY"

Bunty

Message was edited by:

bunty_india

bunty_indiaa at 2007-7-14 1:29:45 > top of Java-index,Java Essentials,Java Programming...
# 3

When you concatinate the data to sql string the characters in the data can break the syntex. Thats what happerning

Where is an example.

Lets say that you have a document information in following in following variables

Name of the document in "doc_name",

Content in variable "doc_content"

and you want to insert them in to table DOCUMENT_TAB

and the JDBC connection is con

PreparedStatement ps = con.prepareStatement("INSERT INTO document_tab (name,content) VALUES(?, ?)");

ps.setString(1,doc_name);//this will set the value for 1st '?'

ps.setString(2,doc_content);//this will set the value for 2nd '?'

//now execute

ps.executeUpdate();

//close the statement

ps.close();

LRMKa at 2007-7-14 1:29:45 > top of Java-index,Java Essentials,Java Programming...
# 4

Thanks LRMK,

But what about the string contain inverted commas (')

will it take it into database?

Example

RFID and auto-ID industry representatives, as well as privacy advocates and concerned citizens, gathered to discuss Homeland Security's "Use of RFID in Human Identification" report.

Bunty

bunty_indiaa at 2007-7-14 1:29:45 > top of Java-index,Java Essentials,Java Programming...
# 5
it is working thanksbunty.dev@gmail.com
bunty_indiaa at 2007-7-14 1:29:45 > top of Java-index,Java Essentials,Java Programming...