In this tutorials will teach you Java connect with MongoDb Database with Swing Application.MongoDb is a NOSQLdatabase.how to do the simple Search connect with MongoDb Database teach step by step here.How to connect java in to MongoDb Database.
Establish the database Connection with Java and MongoDb Database
First Install the mongodb and robo mongo i attched the video link below.
If you don’t have a idea about MongoDb Database . it is simple to learn i have attached the video link below.
After watch above video links i hope now you have clear idea about mongodb.
h3>Establish the database Connection
mongo = new MongoClient(“localhost”,27017); This is port where your robo mongodb is connected
dbconnection = mongo.getDatabase(“school”); This is database name
collection= dbconnection.getCollection(“records”); This is a table name
MongoClient mongo; MongoDatabase dbconnection; MongoCollection<org.bson.Document> collection; public void Connect() { mongo = new MongoClient("localhost",27017); dbconnection = mongo.getDatabase("school"); collection= dbconnection.getCollection("records"); System.out.println("connect"); }
after done the connet() method call inside the constructor of the class
public Registation() { initComponents(); Connect(); }
Paste the Code Inside the Find Button
BasicDBObject search = new BasicDBObject(); search.put("name", txtName.getText()); MongoCursor<Document> cursor = collection.find(search).iterator(); while (cursor.hasNext()) { System.out.println(cursor.next()); }
Conditional statements in Python allow us to control the flow of execution based on conditions.…
A Java Bean is a reusable software component that follows a specific set of conventions.…
Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…
Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…
Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…
Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…