如何在 pgAdmin III 上使用命令 "insert into" 在字符串中使用单引号
How to use simple quotes in strings using the command "insert into" on pgAdmin III
我制作了一个 Java 代码来读取文本文档,并 returns 我复制并粘贴了 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 将这个字符合并到字符串中?
你要找的是如何转义特殊字符。因此,您必须使用 '
转义 '
,这意味着您将以 ''
结尾,就像这样插入:
insert into table (description)
values ('this is a description where '' this simple quote messes up the command');
编辑:因为您使用 java 代码更新了您的问题。对于 java,您还需要转义您的特殊字符,在本例中为 \
。您的代码将是:
if(Currentline.charAt(i) == '\'' ){ ... }
我制作了一个 Java 代码来读取文本文档,并 returns 我复制并粘贴了 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 将这个字符合并到字符串中?
你要找的是如何转义特殊字符。因此,您必须使用 '
转义 '
,这意味着您将以 ''
结尾,就像这样插入:
insert into table (description)
values ('this is a description where '' this simple quote messes up the command');
编辑:因为您使用 java 代码更新了您的问题。对于 java,您还需要转义您的特殊字符,在本例中为 \
。您的代码将是:
if(Currentline.charAt(i) == '\'' ){ ... }