Question : Java & MYSQL

hi there
i have written a java program to parse an html page and save its content into mysql.
now i can able to parse the html page, but when i try to insert those data into mysql , it says " error in the sql query".

i use mediumblob data type .. is it the right data type to store those html contents or i have to use some other data types???

any suggestions????

Answer : Java & MYSQL

I would say that the problem is that your text2insert string has a ' character somewhere in it which is interpreted as the end of the string. Take a simple example of trying to insert the string

String text2insert = "goat's";

Your SQL statement then becomes...

INSERT INTO feedback.html(data) VALUES('goat's');

Hopefully you can easily see how this creates a syntax error.

The normal way that you might approach this is with PreparedStatements, with code like the below...


PreparedStatment stmt = con.prepareStatement("INSERT INTO feedback.html(data) VALUES(?);");
stmt.setBytes(1, text2insert.getBytes());
stmt.execute();

(Note: that I haven't played with BLOB's or MySQL in Java, but my quick research leads me to believe that using a byte[] is the correct way to deal with BLOB columns in MySQL)

This way there are no issues with special characters, escaping, security holes, etc that you get with trying to build your sql string manually.
Random Solutions  
 
programming4us programming4us