INSERT statement to MS Access

Hi,

I am trying to insert this into my database but because of the speech mark I keep getting an error

INSERT INTO database (field1, field2) VALUES ('Don't do that', 'Stop it')

The ' in (don't) means I keep getting an SQL error. Is there anyway round this.

Thanks

Dave

[312 byte] By [houseofwraitha] at [2007-11-27 5:25:57]
# 1
Yes, by using PreparedStatement. With this you can avoid SQL injections.Check here for a tutorial: http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
BalusCa at 2007-7-12 14:46:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

you can also use double ' like that:

INSERT INTO database (field1, field2) VALUES ('Don''t do that', 'Stop it')

but using a PreparedStatement is more elegant and easier to get optimized by the server (valid at least for Oracle)

[]

S_i_m_ua at 2007-7-12 14:46:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
If you are in a hurry use double ' . But using prepared statement is the professional approach
javamonka at 2007-7-12 14:46:25 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...