Java

Search using Java MongoDb

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.

Lets do the Search form

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()); 
        }

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

GitHub Copilot vs Microsoft Copilot Best AI Tool to Use in 2025

GitHub is a powerful tool used by teams and developers around the globe. This guide is…

2 days ago

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

6 days ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

1 week ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

1 week ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

1 week ago

Google Gemini AI Free AI Tool for Students & Creators

Google Gemini AI is among the top talked about developments. What exactly is it? What…

2 weeks ago