Daniol Thomas has Published 197 Articles

Get Random record from MongoDB?

Daniol Thomas

Daniol Thomas

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

2K+ Views

To get a random record from MongoDB, you can use aggregate function. The syntax is as follows:db.yourCollectionName.aggregate([{$sample:{size:1}}]);To understand the above syntax, let us create a collection with some documents. The query to create collection is as follows:>db.employeeInformation.insert({"EmployeeId":1, "EmployeeName":"Maxwell", "EmployeeAge":26}); WriteResult({ "nInserted" : 1 }) >db.employeeInformation.insert({"EmployeeId":2, "EmployeeName":"David", "EmployeeAge":25}); WriteResult({ "nInserted" : ... Read More

The contains() method of Java AbstractCollection class

Daniol Thomas

Daniol Thomas

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

127 Views

The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.The syntax is as follows:public boolean contains(Object ele)Here, ele is the element to be checked for existence.To ... Read More

Write an JDBC example for inserting value for Clob data type into a table?

Daniol Thomas

Daniol Thomas

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

2K+ Views

Assume we already have a table named MyData in the database with the following description.+---------+--------------+------+-----+---------+-------+ | Field   | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | Name | varchar(255) | YES | ... Read More

Write an JDBC example to retrieve Clob value from a table using the getCharacterStream() method?

Daniol Thomas

Daniol Thomas

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

675 Views

The ResultSet interface provides the method named getClob() to retrieve clob datatype from a table in a database. In addition to this it also provides a method named getCharacterStream()Like getClob() this method also accepts an integer representing the index of the column (or, a String value representing the name of ... Read More

Can we disable JComboBox arrow button in Java?

Daniol Thomas

Daniol Thomas

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

624 Views

Yes, we can do that using removeArrow() method.The following is an example to disable JComboBox arrow button:Exampleimport java.awt.Component; import java.awt.Container; import javax.swing.*; public class SwingDemo {    public static void main(String[] args) {       String[] strValues = {"One", "Two"};       JComboBox comboBox = new JComboBox(strValues);   ... Read More

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

318 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

106 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

Advertisements