I am trying to write simple Java code that shows MongoDB collections on the console. I added mongodb-driver-3.0.0.jar to my classpath.
But when I try to execute the code, it gives me the following error in the database connection string:
An exception in the thread "main" java.lang.NoClassDefFoundError: com / mongodb / connection / BufferProvider at com.chintan.app.MongoDbJdbc.main (MongoDbJdbc.java:12) Called: java.lang.ClassNotFoundException: com.mongbconn BufferProvider at java.net.URLClassLoader $ 1.run (Unknown source) in java.net.URLClassLoader $ 1.run (Unknown source) in java.security.AccessController.doPrivileged (native method) in java.net.URLClassLoader.findClass (Unknown source) ) in java.lang.ClassLoader.loadClass (Unknown source) in sun.misc.Launcher $ AppClassLoader.loadClass (Unknown source) in java.lang.ClassLoader.loadClass (Unknown source) ... 1 more
The following is a snippet of code:
public static void main(String[] args) { MongoClient mongoClient = new MongoClient("localhost", 27017); //Exception @SuppressWarnings("deprecation") DB db = mongoClient.getDB("mydb"); System.out.println("Database connection successfull."); ... ... }
What is the problem? Do I need to add another jar to the classpath or is there a problem with the version?
java mongodb
Chintan patel
source share