简体   繁体   English

Java:无法访问com.mongodb.ServerAddress-Java未连接到MongoDB

[英]java: cannot access com.mongodb.ServerAddress - java not connecting to MongoDB

I tried to connect MongoDB Database to java using the following code. 我尝试使用以下代码将MongoDB数据库连接到Java。 https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.5.0/mongodb-driver-3.5.0.jar - this is the jar file which I added to the java library,I tried other version as well.I'm using Intellij Idea IDE. https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.5.0/mongodb-driver-3.5.0.jar-这是我添加到Java库中的jar文件,我也尝试了其他版本。我正在使用Intellij Idea IDE。 I have already set up the Mongodb server and created a Database. 我已经设置了Mongodb服务器并创建了一个数据库。 Please propose me a suitable solution. 请为我提出一个合适的解决方案。 Thank you in advance !! 先感谢您 !!

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;

public class Main {
    public static void main (String[]args){
        MongoClient mongoClient = new MongoClient("localhost",27017);
        System.out.println(" connection successful");

    }
}

The following error occurred 发生以下错误

Error:(10, 35) java: cannot access com.mongodb.ServerAddress
  class file for com.mongodb.ServerAddress not found
C:\Users\IntizarR\IdeaProjects\couseWorkV1\src\MainLogin\Main.java  

首先检查mongodb在命令提示符下工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM