com.imos.sample.MongoDBJDBC.java Source code

Java tutorial

Introduction

Here is the source code for com.imos.sample.MongoDBJDBC.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imos.sample;

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

/**
 *
 * @author Pintu
 */
public class MongoDBJDBC {

    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");
            //         boolean auth = db.authenticate(myUserName, myPassword);
            //         System.out.println("Authentication: "+auth);

        } catch (Exception e) {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
    }
}