您的位置:程序门 -> java -> j2ee / ejb / jms



arraylist的读取问题。。希望大家来看看~


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


arraylist的读取问题。。希望大家来看看~[已结贴,结贴人:haiguanglin007]
发表于:2007-05-29 16:24:15 楼主
package   myfly.book;
import   myfly.database.sqlbean;
import   java.sql.resultset;
import   java.util.iterator;
import   java.util.arraylist;
public   class   bookdeliver   {
        public   arraylist   bookdeliver;
  private   string   type;
    public   void   settype(string   type)
        {
        this.type=type;
       
        }
    public   string   gettype()
        {
        return   type;
       
        }
        public   void   bookdeliver()
      {
     
      }
      public   void   getquery()
      {
      string   str= " ";
      str= "select   *   from   dileverclass ";
    try{
      sqlbean   ben=new   sqlbean();
      resultset   rs=ben.EXECutequery(str);
      bookdeliver=new   arraylist();
      while(rs.next())
      {
      bookdeliver   dd=new   bookdeliver();
      dd.settype(rs.getstring( "delivertype "));
      bookdeliver.add(dd);
      }
     
      }catch(exception   e)
      {
      system.out.println( "出错了哦 ");
      }
    }
    public   static   void   main(string[]   args)
      {
      bookdeliver   dd=new   bookdeliver();
      dd.getquery();
    object[]   a=dd.bookdeliver.toarray();
    iterator   ite=dd.bookdeliver.iterator();

      while(ite.hasnext())
    system.out.print(ite.next());
}
以上是我写的代码,但是在输出时的值和数据库里就不一样???
本来是44   输出myfly.book.bookdeliver@1e04cbf,在疑惑中~~
发表于:2007-05-29 16:26:491楼 得分:0
bookdeliver   dd=new   bookdeliver();
dd.settype(rs.getstring( "delivertype "));
bookdeliver.add(dd);

看你装的什么,取的什么
发表于:2007-05-29 16:37:412楼 得分:0
我取的是数据库里delivertype里的字段~~
发表于:2007-05-29 16:38:443楼 得分:0
delivertype是表里的一个字段~
发表于:2007-05-29 16:40:014楼 得分:5
你装进的是bookdeliver实例,你怎么能够直接system.out.print(ite.next());
发表于:2007-05-29 16:41:415楼 得分:10
package   myfly.book;
import   myfly.database.sqlbean;
import   java.sql.resultset;
import   java.util.iterator;
import   java.util.arraylist;
public   class   bookdeliver   {
public   arraylist   bookdeliver;
private   string   type;
public   void   settype(string   type)
{
this.type=type;

}
public   string   gettype()
{
return   type;

}
public   void   bookdeliver()
{

}
public   void   getquery()
{
string   str= " ";
str= "select   *   from   dileverclass ";
try{
sqlbean   ben=new   sqlbean();
resultset   rs=ben.EXECutequery(str);
bookdeliver=new   arraylist();
while(rs.next())
{
bookdeliver   dd=new   bookdeliver();
dd.settype(rs.getstring( "delivertype "));
bookdeliver.add(dd);
}

}catch(exception   e)
{
system.out.println( "出错了哦 ");
}
}
public   string   tostring()
{
return   type;
}
public   static   void   main(string[]   args)
{
bookdeliver   dd=new   bookdeliver();
dd.getquery();
object[]   a=dd.bookdeliver.toarray();
iterator   ite=dd.bookdeliver.iterator();

while(ite.hasnext())
system.out.print(ite.next());
}
发表于:2007-05-29 16:44:066楼 得分:5
因为你装进去的一个对象,而你在你system.out.print(ite.next());的时候默认调用这个对象的tostring方法。tostring方法是从java.lang.object继承来的,object的tostring方法默认实现是取当前对象的哈希码,所以会有你上面的输出
发表于:2007-05-29 16:46:267楼 得分:0
那该怎么办,把他转化为数组后输出??
发表于:2007-05-29 16:49:518楼 得分:0
我在eclipse里面找不到arraylist很好的输出的方法~
发表于:2007-05-29 17:01:419楼 得分:0
谢谢你   ima(男的不会,会的不男)


快速检索

最新资讯
热门点击