Java MongoDB : Query document

In this tutorial, we show you few common ways to get or query document from collection. Test Data Insert 5 dummy documents for testing. { "_id" : { "$oid" : "id"} , "number" : 1 , "name" : "mkyong-1"} { "_id" : { "$oid" : "id"} , "number" : 2 , "name" : "mkyong-2"} { …

Read more

Java MongoDB : Get collection from database

In Java, you can use db.getCollection(“your collection name”) to get a single collection to use. DBCollection collection = db.getCollection("yourCollection"); If you do not know the collection name, use db.getCollectionNames() to get the entire list of collection names from a selected database. DB db = mongo.getDB("yourdb"); Set<String> collections = db.getCollectionNames(); for (String collectionName : collections) { …

Read more

Spring JdbcTemplate Querying Examples

Here are a few examples to show you how to use Spring JdbcTemplate to query or extract data from database. Technologies used : Spring Boot 2.1.2.RELEASE Spring JDBC 5.1.4.RELEASE Maven 3 Java 8 In Short: jdbcTemplate.queryForObject for single row or value jdbcTemplate.query for multiple rows or list Note The article is updated from Spring core …

Read more