0

I've run mongod.exe on windows and trying to connect to client from Java. This is my code. I've already added mongo jar required. When I try to run this, it gives me

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/connection/BufferProvider at line

MongoClient mongoClient = new MongoClient( "localhost" , 27017 );

Here's my code

import com.mongodb.MongoClient;
import com.mongodb.DB;

public class MongoDB {

   public static void main( String args[] ) {

      try{

         // To connect to mongodb server
         MongoClient mongoClient = new MongoClient( "localhost" , 27017 );

         // Now connect to your databases
         DB db = mongoClient.getDB( "test" );
         System.out.println("Connect to database successfully");

      }catch(Exception e){
         System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      }
   }
}
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122

0 Answers0