How to install and connect MongoDb in Netbeans?
I'm using the MongoDB Java driver in a Java web app. Whenever I'm doing a query, or can I keep it open and run other queries on it and close it when my application ends?
You should create DAL object which will handle low level Database CRUD operation, And this object will be singleton as "Piu" suggested. All the methods inside of this object will handle creating/opening/closing connection (on application Exit). This way you will in future you will be free to change to other DB solution and change only the DAL class. On your question, in my opinion you should leave the connection open if you will communicate with the DB a lot. But if you will need to access to DB once a you start the application and on exit and the application execution duration is not short it is safe to close and reopen the connection.
When you create an instance of class MongoClient. Your connection will keep by default. It only close when you use method close() to close it. If you want to open and run other query on it (all query will reuse this connection), you can use the pattern singleton to create only one instance of MongoClient. This pattern will re-create your connection if it is null.
What methods should be contained in the DAO? [closed]
How to build multi dex into apk by maven?
Stream videos in client app using Ajax and java Restlet
Am able to store the image in my computer drive. but unable to display on page
How can I use threads in standard JAX-RS?
Spring 4.0 Jquery Ui autocomplete 406 Not Acceptable Error
Priority of ActiveMQ configuration via URI
Quartz or java timer service for database polling
Method execution after fields are initialized
Lambda expression in Iterable implementation
How to sort books in java [closed]
List files in a package from Android App returns null
Hibernate and MySQL connection - java.net.ConnectException: Connection refused: connect. The driver has not received any packets from the server
Java Swing getvalue from combobox object
JFileChooser hangs the application
Java Android Sockets Threading