-1
import java.io.File;
import com.db4o.Db4o;
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Query;

public class Student {

private String name;

public AlumnoBDOO(String name){
    this.name = name;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public static void main(String[] args) {
    ObjectContainer bd = Db4oEmbedded.openFile("students.db4o");
    try {

        Student s1 = new Student("Carl");
        bd.store(s1)
        showStudents(bd);

       } catch (Exception e) {
           e.printStackTrace();
       } finally {
           bd.close();
       }
    }

public static void showResult(ObjectSet rs){
    System.out.println("Retrieved "+rs.size()+" objects");
    while(rs.hasNext()){
        System.out.println(rs.next());
    }
}

public static void showStudents(ObjectContainer bd){
    Query query = bd.query();
    query.constrain(Student.class);
    query.descend("name");
    ObjectSet rs = query.execute();
    showResult(rs);
}

}

I just simply want to store a Student in the db4o database but when I want to retrieve all of them it outputs like this:

Student@61070a02

I'm using Eclipse Juno and db40 v.8.0 which I already added as external jar. Why am I getting those weird characters instead of "Carl"?

seRgiOOOOOO
  • 91
  • 2
  • 2
  • 8

1 Answers1

1

That is not weired, but the default implementation of the toString() method. To get meaningfull information you should override this method in your Student class.

PeterMmm
  • 24,152
  • 13
  • 73
  • 111
  • Oh thanks. I already tried the toString method but directly in the printing line, not implementing it as method :) – seRgiOOOOOO Nov 27 '14 at 15:05