代码
package com.yansl;
import java.net.UnknownHostException;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
public class MongodbTest {
private Mongo mong=null;
private DB db=null;
private DBCollection dbc=null;
public MongodbTest()
{
try {
mong=new Mongo();
System.out.println(mong);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MongoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db=mong.getDB("MyTest");
System.out.println(db);
dbc=db.getCollection("table1");
System.out.println(dbc);
}
public void selectAll(){
System.out.println("查询table1中的所有数据:");
//得到查询
DBCursor cur = dbc.find();
//遍历结果
while(cur.hasNext()){
System.out.println(cur.next());
}
}
public static void main(String[] args) {
MongodbTest m=new MongodbTest();
m.selectAll();
}
}
输出和错误信息
————————————————————————————————————————————————
Mongo: 127.0.0.1:27017
MyTest
table1
查询table1中的所有数据:
2012-3-12 17:47:21 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:23 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:24 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:25 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:26 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告: null
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:409)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
2012-3-12 17:47:27 com.mongodb.DBTCPConnector$MyPort error
严重: MyPort.error called
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
Exception in thread "main" com.mongodb.MongoException$Network: can't call something
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:209)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:354)
at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
at com.yansl.MongodbTest.selectAll(MongodbTest.java:45)
at com.yansl.MongodbTest.main(MongodbTest.java:52)
Caused by: java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.call(DBPort.java:65)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
... 8 more
相关文章
- [置顶] 关于离线安装genymotion时出现的错误的解决办法
- 第一次安装tomcat报错,出现failed to install tomcat8 service错误
- 第一次安装10g到最后提示:ORA-28547连接服务器失败,可能是NET8管理错误。
- [置顶] 关于离线安装genymotion时出现的错误的解决办法
- mongodb安装错误以及原理
- windows安装MongoDB进度条卡住,window安装mongo系统错误 2,系统错误5的解决办法(转载)
- [置顶] Mongodb错误,第一次安装没有经验
- 安装MongoDB启动时报错‘发生系统错误2’的解决办法
- 新mac 下第一次 安装 mongodb 步骤
- MongoDB作为Windows服务来安装 错误1053:服务没有及时响应启动或控制请求