Daniol Thomas has Published 209 Articles

How do we insert/store a file into MySQL database using JDBC?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

4K+ Views

In general, the contents of a file are stored under Clob (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT) datatype in MySQL database.JDBC provides support for the Clob datatype, to store the contents of a file in to a table in a database.The setCharacterStream() method of the PreparedStatement interface accepts an integer representing the index ... Read More

Remove object from array in MongoDB?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

1K+ Views

To remove object from an array in MongoDB, you can use $pull operator. The syntax is as follows:db.yourCollectionName.update( {'_id':ObjectId("5c6ea036a0c51185aefbd14f")}, {$pull:{"yourArrayName":{"yourArrayFieldName":yourValue}}}, false, true);To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:> db.removeObject.insertOne({"CustomerName":"Maxwell", "CustomerAge":23, ... "CustomerDetails":[ ... { ... Read More

The remove() method of AbstractList class in Java

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

249 Views

Remove an element at a specified position from the list using the remove() method. The position is to be set as index parameter in the method itself. It returns the element which is removed.The syntax is as follows:public E remove(int index)Here, index is the index from where you want to ... Read More

Count the number of items in an array in MongoDB?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

5K+ Views

To count the number of items in an array, you can use $size operator. The syntax is as follows:db.yourCollectionName.aggregate({$project:{anyFieldName:{$size:"$yourArrayName"}}}).prett y();To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:>db.getSizeOfArray.insertOne({"StudentId":1, "StudentName":"Larry", "StudentMarks":[87, 34, 5 6, 77, 89, 90]}); ... Read More

The get() method of CopyOnWriteArrayList in Java

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

63 Views

The get() method of CopyOnWriteArrayList class returns the element at the specified position in this list.The syntax is as follows:E get(int index)Here, the parameter index is the position from where you want the element.To work with CopyOnWriteArrayList class, you need to import the following package:import java.util.concurrent.CopyOnWriteArrayList;The following is an example ... Read More

How to update the _id of a MongoDB Document?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

10K+ Views

You cannot update it but you can save a new id and remove the old id. Follow some steps in order to update the _id of a MongoDB. The steps are as follows:Step1: In the first step, you need to store ObjectId into a variable.anyVariableName=db.yourCollectionName.findOne({_id:yourObjectIdValue)});Step 2: In the second step, ... Read More

Best way to store date/time in MongoDB?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

1K+ Views

There are two different ways by which you can store date/time in MongoDB. In the first approach, you can use Date objects like JavaScript. The Date object is the best way to store date/time in MongoDB. The syntax is as follows:new Date();In the second approach, you can use ISODate(). The ... Read More

How to remove a field completely from a MongoDB document?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

785 Views

You can use $unset operator to remove a field completely from a MongoDb document. The syntax is as follows:db.yourCollectionName.update({}, {$unset: {yourFieldName:1}}, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents are as follows:> db.removeFieldCompletlyDemo.insertOne({"StudentName":"Larry", "StudentFavouriteSubject": ["Java", "C", ... Read More

Add new field to every document in a MongoDB collection?

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

2K+ Views

To add new field to every document in a MongoDB collection, you can use $set operator. The syntax is as follows:db.yourCollectionName.update({}, { $set: {"yourFieldName": yourValue} }, false, true);To understand the above syntax, let us create a collection with some documents. The query to create a collection with documents is as ... Read More

Period hashCode() method in Java

Daniol Thomas

Daniol Thomas

Updated on 30-Jul-2019 22:30:25

98 Views

The hash code value of the Period can be obtained using the hashCode() method in the Period class in Java. This method requires no parameters and it returns the hash code value of the Period.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo {   ... Read More

Advertisements