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.
How can I add combobox in cell table as drag and drop in Java?
Springs 3.6.4 +form bindingerror
extract my java app with its database from netbeans
Dispatcher servlet return unrenderd JSP (Java Config)
JTextArea displaying weird error message
Assign text to JLabels from ArrayList
What does this regex syntax actually mean in Java?
Converting a number to a user chosen base
How to call a stored procedure in JDBC
how to use goto in java
Android - TouchImageView Full view issue
how to get all value checkbox when next pagination (jsp and servlet)
Continue code execution after new JFrame is created and then closed
Handling different soap actions in spring integration
expanding links in the tweets in twitter using twitter 4j
Programatically enabling Mobile data in Android