0

我是 sqlite 的初学者,我使用它我别无选择,我用 java 编码,我有一个请求,它应该作为 reslutat 两列返回,但它返回任何东西,结果集是 org.sqlite.RS@..,请我需要这方面的帮助,提前谢谢你。

        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;
}

   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+"'",false);  logger.info("ma liste :"+ls);
   }}

我的文件日志包含什么

 INFO  [com.sfr.price.functionalTest.commons.SQLBase.executeSelect](82) [] ret :busitypid,attblabel
 INFO  [com.sfr.price.functionalTest.commons.SQLBase.executeSelect](85) [] busitypid
 INFO  [com.sfr.price.functionalTest.commons.SQLBase.executeSelect](85) [] attblabel
 INFO  [com.sfr.price.functionalTest.commons.SQLBase.executeSelect](90) [] 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'
 INFO  [com.sfr.price.functionalTest.commons.SQLBase.executeSelect](93) [] mon resultSet:org.sqlite.RS@24c672
 INFO  [com.sfr.price.functionalTest.scenario.impl.AJLINGE.etapeParametrerOption](799) [] ma liste :[]
4

1 回答 1

0

打印结果集时得到的org.sqlite.RS@24c672原因是该类没有覆盖基对象类中toString()的默认实现。根据SQLiteJDBC 文档,您应该能够遍历 ResultSet 并相应地打印出值。

像这样的东西应该工作:

while (rs.next()) {
    logger.info("busitypid = " + rs.getString("busitypid");
    logger.info("attblabel = " + rs.getString("attblabel");
}
rs.close();

另外,我不明白你的 boolean 的目的All。(注意:Java 风格约定表明此变量应命名为all,首字母小写。)由于while循环和if语句的编写方式,您最终要么打印列标题,要么打印结果集的内容. 根据您的日志文件的内容,我假设您已通过All = false- 这将使您的输出正确。

于 2012-06-25T15:14:06.527 回答