public class DataService {
private static DataService dataService;
private static MongoClient mongoClient;
private static MongoDatabase db;
static {
try {
mongoClient = new MongoClient( "localhost" , 27017 );
db = mongoClient.getDatabase("mydb");
} catch (Exception e) {}
}
private DataService() {}
public static DataService getInstance() {
if (dataService == null) {
dataService = new DataService();
}
return dataService;
}
public MongoDatabase getDB() {
return db;
}
}
这种糟糕的设计是否可以访问MongoDB?这甚至是单身人士吗?如果这很糟糕,有人可以建议我找一个好的解决方案...... 对不起我的英语不好。谢谢