Hsqldb single quote character

大城市里の小女人 提交于 2019-12-12 10:07:46

问题


How can I insert single quote character to Hsqldb table? Escape character doesn't work for the problem.


回答1:


There are two ways.

  1. Use two single quotes. For example INSERT INTO T VALUES 'escap''d'

  2. Use a Unicode string, which can contain a Unicode escape. For example INSERT INTO T VALUES U&'escap\0027d'

Both examples insert the string escap'd into the table.




回答2:


The question is old, but I found the answer by fredt but it led me astray because it doesn't actually do what the original poster requested which is insert a single quote. Instead it inserts escap'd which is not what I wanted to do.

This may have been the only way in the past (Fred would know better than me), but the easiest way in hsqldb to insert a single quote now is to just make a prepared statement in java (p_insert) and set the String:

p_insert.setString(1,"'"); p_insert.executeUpdate();

This will actually put a single quote in the database, at least in version 2.3.2. To retrieve it from the database, you will need to use double single quotes in your SELECT statement.



来源:https://stackoverflow.com/questions/13397186/hsqldb-single-quote-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!