2016-08-16 57 views
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++; 
     } 
     }} 

回答

1

当蒙戈客户端与Java代码的MongoDB数据库连接。如果你没有使用HASH Map,那么就不可能使用泛型。如果你正在使用,那么编译问题就会到来。