mongodb java 拒绝连接,无法使用Java连接到MongoDB

I'm trying to write a Java program that will connect to a MongoDB database. I already have the IP address, port, userDB, username, and password of the database I'm trying to access.

I have the mongodb-driver-3.0.0.jar file set as a referenced library in Eclipse. I created a MongoDBDriver.java file in the src folder (shown below):

import com.mongodb.MongoClient;

public class MongoDBDriver {

public static void main(String[] args) {

MongoClient client = new MongoClient("10.66.80.152", 27017);

String connectPoint = client.getConnectPoint();

System.out.println(connectPoint);

client.close();

}

}

When I run the script, I get the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError:

com/mongodb/connection/BufferProvider

at MongoDBDriver.main(MongoDBDriver.java:7)

Caused by: java.lang.ClassNotFoundException:

com.mongodb.connection.BufferProvider

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 1 more

So, what am I doing wrong and how can I fix it?

解决方案

Exception means that you have the class path mismatch.

I create small app that connect java and mongodb and do some CURD operations.

eMongoDB-Java-app

I think it will be better solution to connect database.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值