Reputation: 2006
Working with H2 I get this error when I try to write a row with the first element being ABC and the second being [C@26afa68a
Syntax error in SQL statement "INSERT INTO USER VALUES(ABC,[[*]C@F4D5BC9) " expected "), DEFAULT, NOT, EXISTS, SELECT, FROM"; SQL statement:INSERT INTO user VALUES(abc,[C@f4d5bc9) [42001-167]
I don't know if there is a way to get H2 to accept Special Characters, but it would be great to know how to deal with this.
Thanks!
Upvotes: 1
Views: 3151
Reputation: 50087
You should use a PreparedStatement:
PreparedStatement prep = conn.prepareStatement("INSERT INTO USER VALUES(?, ?)");
prep.setString(1, "ABC");
prep.setString(2, "[C@f4d5bc9");
prep.executeUpdate();
prep.close();
Using a PreparedStatement is the preferred solution, because that way you don't have to escape the data. If ABC
and / and [C@f4d5bc9
are constants, you could use:
Statement stat = conn.createStatement();
stat.executeUpdate("INSERT INTO USER VALUES('ABC', '[C@f4d5bc9');
stat.close();
Upvotes: 3