1
我在独立的Java应用程序中使用mongoDB客户端。 我想知道我何时无法在此客户端程序中使用泛型。 下面的代码样本,我使用有什么方法可以使用泛型在MongoDB Client中?
public class MongoDB_Client {
public static void main(String[] args) {
try{
MongoClient monog_Client=new MongoClient("localhost",27017);
DB db=monog_Client.getDB("test");
DBCollection getcCollection=db.getCollection("products");
if(getcCollection.equals("products")) {
DBCollection collection_data = db.getCollection("products1");
System.out.println("Collection products1 getting successfully");
DBObject myDoc = collection_data.findOne();
DBCursor cursor = collection_data.find();
int j =1;
while (cursor.hasNext()) {
System.out.println("Inserted Document: "+j);
System.out.println(cursor.next());
j++;
}
}}