简体   繁体   中英

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

I tried to connect MongoDB Database to java using the following code. 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. I have already set up the Mongodb server and created a Database. 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在命令提示符下工作正常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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