Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping a full string in H2 insert statement

Tags:

java

sql

insert

h2

I am trying to escape a whole string for insert into a longtext or varchar. Basically I have a string full of all types of special characters and special words (ex. LIKE) and I just want to escape the whole thing so that I can insert it into my H2 database.

I've asked a few friends and they said that I should try serializing the data. Is this the proper way to insert random strings into the db? Should I be trying to do this with prepared statements?

Sorry I'm new to H2 and not that great with SQL. Thanks for the help in advance!

like image 404
El Duderino Avatar asked Dec 12 '25 15:12

El Duderino


1 Answers

If you are looking for examples on how to use a PreparedStatement:

  • http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
  • http://en.wikipedia.org/wiki/Prepared_statement#Examples
  • http://www.jdbc-tutorial.com/jdbc-prepared-statements.htm
like image 174
Thomas Mueller Avatar answered Dec 15 '25 09:12

Thomas Mueller