[英]How to use simple quotes in strings using the command “insert into” on pgAdmin III
我制作了一个 Java 代码,该代码读取一个文本文档并向我返回一个 sql 命令列表( insert into
),我将这些命令复制并粘贴到 pgAdmin III 上,以便它可以插入在其数据库中读取的数据。
如您所知, insert into
命令使用简单的引号来包装字符串值,如下所示:
insert into table (description) values ('text from the .txt');
问题是,一些描述在其文本中带有简单的引号,因此,它使 pgAdmin 将它们理解为字符串的结尾:
insert into table (description) values ('this is a description where ' this simple quote messes up the command');
我也必须对 Java 表达式做同样的事情,比如:
if(Currentline.charAt(i) == ''' ){ ... }
所以我可以解决整个问题。
我认为,可能有一种简单的方法可以解决这个问题。 有人知道怎么做吗? 基本上,如何让 pgAdmin 将此字符合并到字符串中?
您正在寻找的是如何转义特殊字符。 因此,您必须转义'
with '
这意味着您将以''
结尾,就像这样插入:
insert into table (description)
values ('this is a description where '' this simple quote messes up the command');
编辑:因为您使用 java 代码更新了您的问题。 对于 java 您还需要转义您的特殊字符,在这种情况下使用\
。 您的代码将是:
if(Currentline.charAt(i) == '\'' ){ ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.