2016-08-16 43 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,那麼就不可能使用泛型。如果你正在使用,那麼編譯問題就會到來。

相關問題