存储包含多种类型字符的字符串

时间:2012-03-20 11:50:25

标签: java

我如何存储

 "CREATE COLUMN VIEW "_USE_BID"."rev26/FREESTYLE" TYPE JOIN WITH PARAMETERS ( joinIndex = "REV26"."SIMPLECOMPANY", joinIndexType = 0, viewAttribute = ('ID', "REV26"."SIMPLECOMPANY", "ID", '', 'default', 'attribute', '', 'rev26/FREESTYLE$ID'), freestyleSearchAttribute = 'ID:0.0', viewAttribute = ('NAME', "REV26"."SIMPLECOMPANY", "NAME", '', 'default', 'attribute', '', 'rev26/FREESTYLE$NAME'), freestyleSearchAttribute = 'NAME:0.0'
" 

作为java中的单个字符串?这是我想要执行的SQL查询。

3 个答案:

答案 0 :(得分:1)

手动逃离“via \”

  

String queryString =“”;把你的陈述放在其中并逃避你的“去   \“

答案 1 :(得分:0)

"CREATE COLUMN VIEW \"_USE_BID\".\"rev26/FREESTYLE\" TYPE JOIN WITH PARAMETERS ( joinIndex = \"REV26\".\"SIMPLECOMPANY\", joinIndexType = 0, viewAttribute = ('ID', \"REV26\".\"SIMPLECOMPANY\", \"ID\", '', 'default', 'attribute', '', 'rev26/FREESTYLE$ID'), freestyleSearchAttribute = 'ID:0.0', viewAttribute = ('NAME', \"REV26\".\"SIMPLECOMPANY\", \"NAME\", '', 'default', 'attribute', '', 'rev26/FREESTYLE$NAME'), freestyleSearchAttribute = 'NAME:0.0'

答案 2 :(得分:0)

你唯一需要做的就是逃避所有的双引号。换句话说,所有“角色都应该改为”......

String sqlStatement = "CREATE COLUMN VIEW \"_USE_BID\".\"rev26/FREESTYLE\" TYPE JOIN WITH PARAMETERS ( joinIndex = \"REV26\".\"SIMPLECOMPANY\", joinIndexType = 0, viewAttribute = ('ID', \"REV26\".\"SIMPLECOMPANY\", \"ID\", '', 'default', 'attribute', '', 'rev26/FREESTYLE$ID'), freestyleSearchAttribute = 'ID:0.0', viewAttribute = ('NAME', \"REV26\".\"SIMPLECOMPANY\", \"NAME\", '', 'default', 'attribute', '', 'rev26/FREESTYLE$NAME'), freestyleSearchAttribute = 'NAME:0.0'";

但是,您的声明中有一些内容可能会鼓励您将其拆分为较小的字符串。例如,ID和NAME列基本上都是相同的语句,因此您可以只使用模板String并将空格替换为列名(在这种情况下为NAME的ID)。例如......

String columnTemplate = "viewAttribute = ('<COLUMN>', \"REV26\".\"SIMPLECOMPANY\", \"<COLUMN>\", '', 'default', 'attribute', '', 'rev26/FREESTYLE$<COLUMN>'), freestyleSearchAttribute = '<COLUMN>:0.0'";

String idColumn = columnTemplate.replaceAll("<COLUMN>","ID");
String nameColumn = columnTemplate.replaceAll("<COLUMN>","NAME");

String joinIndex = "joinIndex = \"REV26\".\"SIMPLECOMPANY\", joinIndexType = 0, " + idColumn + ", " + nameColumn;

String sqlStatement = "CREATE COLUMN VIEW \"_USE_BID\".\"rev26/FREESTYLE\" TYPE JOIN WITH PARAMETERS ( " + joinIndex + ")";

这可以帮助您通过删除重复来更快/更轻松地构造SQL语句,还可以帮助您通过使语句总体上不那么复杂来查找语句中的错误。