Reputation:
i have the following code :
DBCollection collsc = db.getCollection("StudentCourses") ;
BasicDBObject querysc = new BasicDBObject("StudentID",id );
DBCursor curssc = collsc.find(querysc);
while(curssc.hasNext()) {
DBObject e = curssc.next();
System.out.println("You are currently registered for the following modules: ") ;
System.out.println(e.get("CoursesRegistered")) ;
}
This outputs:
You are currently registered for the following modules:
[ "DigitalLogic" "OperatingSystems" , "FundamentalsCSE"]
However i want only the values to be returned from the array, i.e, DigitalLogic, OperatingSystems and FundamentalsCSE. I will use these values to populate a JList. Help please?
Upvotes: 10
Views: 19880
Reputation: 5866
Try to use
BasicDBList e = (BasicDBList) curssc.next().get("CoursesRegistered");
instead of
DBObject e = curssc.next();
and then get value from e.getIndex(index);
Upvotes: 17