我正在使用SQLite,我需要从许多表中进行选择而我正在使用java我的问题是当我将此选择作为结果时,我没有任何东西它返回一个空的arrayList。
public void etapeParametrerOption(String login) throws IOException, SQLException
{
assertTrue( "Texte 'Paramétrer les options' non présent, voir code source HTML dans LogOut",selenium.isTextPresent( "Paramétrer les options" ) );
String [] tab=LogFile.showWSEtAppelCOffrEFrom(login);
List<String>ls=new ArrayList<String>();
for(String itab : tab){
ls=dbCOffrE.executeSelect("SELECT busitypid,attblabel FROM t_article art, t_attribute att , t_srvbrick_attr_article srv WHERE att.attbid = srv.attbid and art.artid = srv.artid and att.modoptidmodifiable = '2' and (att.attbinactivationdate is null or att.attbinactivationdate < date('now')) and art.artshortlabel='"+itab+"'");
logger.info("ma liste :"+ls);
}
public List<String> executeSelect( String ArgRequete, boolean All) throws SQLException
{
String ReturnColumn = ArgRequete.substring( ArgRequete.indexOf( "SELECT" )+ 6, ArgRequete.indexOf( "FROM" ) ).replaceAll(" ","");
List<String> Str = new ArrayList<String>();
logger.info("ret :"+ReturnColumn);
String[] columns=ReturnColumn.split(",");
for(String ico:columns){
logger.info(ico);
} stmt = con.createStatement();
rs = stmt.executeQuery( ArgRequete );
logger.info(ArgRequete);
logger.info("mon resultSet:"+rs);
if ( !All )
{
if ( rs.next() )
{
String result = "";
for(String aColumn : columns){
result += rs.getString(aColumn ) + ",";
logger.info(result);
}
Str.add( result );
}
}
while ( rs.next() && All )
{
String result = "";
for(String aColumn : columns){
result += rs.getString( aColumn ) + ",";
}
Str.add( result );
}
stmt.close();
return Str;
}
因此,当我使用一个简单的请求,例如“从NameTable选择S1,S2,其中Id ='345'”它完美地工作但是这样的请求: SELECT busitypid,attblabel FROM t_article art,t_attribute att,t_srvbrick_attr_article srv WHERE att.attbid = srv.attbid and art.artid = srv.artid and att.modoptidmodifiable ='2'and(att.attbinactivationdate is null or att.attbinactivationdate&lt; date('now'))和art.artshortlabel ='“+ itab +”'“) 它实际上崩溃了。
在我的日志文件中我得到了结果: INFO com.sfr.price.functionalTest.commons.SQLBase.executeSelect [] ret:busitypid,attblabel INFO com.sfr.price.functionalTest.commons.SQLBase.executeSelect [] busitypid INFO com.sfr.price.functionalTest.commons.SQLBase.executeSelect [] attblabel INFO com.sfr.price.functionalTest.commons.SQLBase.executeSelect [] SELECT busitypid,attblabel FROM t_article art,t_attribute att,t_srvbrick_attr_article srv WHERE att.attbid = srv.attbid and art.artid = srv.artid and att.modoptidmodifiable = '2'和art.artshortlabel ='8001P' INFO com.sfr.price.functionalTest.commons.SQLBase.executeSelect [] mon resultSet:org.sqlite.RS@24c672 INFO com.sfr.price.functionalTest.scenario.impl.AJLINGE.etapeParametrerOption [] ma liste:[]
答案 0 :(得分:0)
看起来附加的代码与您附加的日志文件不对应。在日志文件中,我们可以看到执行以下查询:
SELECT busitypid,attblabel FROM t_article art, t_attribute att , t_srvbrick_attr_article srv WHERE att.attbid = srv.attbid and art.artid = srv.artid and att.modoptidmodifiable = '2' and art.artshortlabel='8001P'
在代码片段中您有以下查询
SELECT busitypid,attblabel FROM t_article art, t_attribute att , t_srvbrick_attr_article srv WHERE att.attbid = srv.attbid and art.artid = srv.artid and att.modoptidmodifiable = '2' and (att.attbinactivationdate is null or att.attbinactivationdate < date('now')) and art.artshortlabel='"+itab+"'"
请注意WHERE子句中att.attbinactivationdate的附加检查。也许您实际执行的查询不会返回任何值。