我试图用java驱动程序处理MongoDB异常,但是没有一个try try异常被抛出?
try
{
MongoClient client = new MongoClient("localhost", 27017);
DB database = client.getDB("example");
}catch(Exception e){
e.printStackTrace();
}
你能帮我吗 ?
您的第一个查询会出现异常:
try
{
MongoClient client = new MongoClient("localhost", 27017);
DB database = client.getDB("example");
database.getCollection("foo");
}catch(Exception e){
e.printStackTrace();
}
注意:不推荐使用getDB,请使用getDatabase