Print Object to Console in a MongoDB Script

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

4K+ Views

You can use printjson() method to print to console an object in a MongoDB script. The syntax is as follows −printjson({yourFieldName”:yourValue”, ........N});You can use JSON.stringify() along with print() function. The syntax is as follows minus;print ( JSON.stringify( { {yourFieldName”:yourValue”, ........N} } ));Let us implement the above syntax to print object in Mongo script. The query is as follows −>printjson({"UserId":101, "UserName":"John", "UserCoreSuject":["Java", "MongoDB", "MySQL", "SQL Server"]});The following is the output −{    "UserId" : 101,    "UserName" : "John",    "UserCoreSuject" : [       "Java",       "MongoDB",       "MySQL",       "SQL Server"   ... Read More

Move ResultSet Pointer to Default Position Using JDBC

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

656 Views

The beofreFirst() method of the ResultSet interface moves the cursor/pointer to its default position i.e. before the first record.rs.beforeFirst();Assume we have a table named cricketers_data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1 | Shikhar     | Dhawan     | 1981-12-05    | Delhi          | India       | | 2 | Jonathan    | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | 3 | Lumara      | Sangakkara ... Read More

Query Top N Rows in MongoDB

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

3K+ Views

To query on top N rows in MongoDB, you can use aggregate framework. Let us create a collection with documents> db.topNRowsDemo.insertOne({"StudentName":"Larry", "Score":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca26eee6304881c5ce84b91") } > db.topNRowsDemo.insertOne({"StudentName":"Chris", "Score":45}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca26ef66304881c5ce84b92") } > db.topNRowsDemo.insertOne({"StudentName":"Mike", "Score":65}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca26efe6304881c5ce84b93") } > db.topNRowsDemo.insertOne({"StudentName":"Adam", "Score":55}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca26f066304881c5ce84b94") } > db.topNRowsDemo.insertOne({"StudentName":"John", "Score":86}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca26f0f6304881c5ce84b95") }Following is the query to display all documents from a collection with the help of find() method> ... Read More

Generate Large Random Numbers in Java

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

722 Views

For large random numbers, use BigInteger type in Java. At first, create a Random object −Random randNum = new Random();Now, declare a byte array and generate random bytes −byte[] b = new byte[max]; randNum.nextBytes(b);Now, generate a large random number with BigInteger type −BigInteger bigInt = new BigInteger(b);Example Live Demoimport java.math.BigInteger; import java.util.Random; public class Demo {    public static void main(String... a) {       int max = 10;       Random randNum = new Random();       byte[] b = new byte[max];       randNum.nextBytes(b);       // BigInteger type       BigInteger bigInt ... Read More

Get Today's Date in YYYY-MM-DD Format in MySQL

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

3K+ Views

To get today’s date in (YYYY-MM-DD) format in MySQL, you can use CURDATE().Following is the query to get the current date:mysql> SELECT CURDATE();This will produce the following output:+------------+ | CURDATE() | +------------+ | 2019-04-09 | +------------+ 1 row in set (0.00 sec)You can also use NOW() for this. Following is the query:mysql> SELECT DATE(NOW());This will produce the following output+-------------+ | DATE(NOW()) | +-------------+ | 2019-04-09 | +-------------+ 1 row in set (0.00 sec)

LinkedBlockingDeque in Java

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

384 Views

The LinkedBlockingDeque Class in Java has a blockingdeque that is optionally bounded and based on linked nodes. This class implements the Collection interface as well as the AbstractQueue class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.LinkedBlockingDeque; public class Demo {    public static void main(String[] args) {       LinkedBlockingDeque lbDeque = new LinkedBlockingDeque();       lbDeque.add("James");       lbDeque.add("May");       lbDeque.add("John");       lbDeque.add("Sara");       lbDeque.add("Anne");       System.out.println("Size of LinkedBlockingDeque is: " + lbDeque.size());     ... Read More

Java Signature getAlgorithm Method

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

234 Views

The name of the algorithm for the signature object can be obtained using the method getAlgorithm() in the class java.security.Signature. This method requires no parameters and it returns the name of the algorithm for the signature object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          Signature signature = Signature.getInstance("SHA256withRSA");          String algorithm = signature.getAlgorithm();          System.out.println("The Algorithm is: " + algorithm);       } catch (NoSuchAlgorithmException e) { ... Read More

Check if ArrayList is Empty for ListView in Android

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

441 Views

This example demonstrates How to check arraylist is empty for Listview in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.               In the above code, we have taken name and record number as Edit text, when user click on save button it will store the data into ... Read More

Get Android Device Brand Name Programmatically

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

1K+ Views

This example demonstrate about How to get programmatically android device brand name.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken text view to show device brand name .Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.app.ProgressDialog; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; ... Read More

Execute SQL SELECT Statement in JSP

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

3K+ Views

The tag executes an SQL SELECT statement and saves the result in a scoped variable.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultsqlSQL command to execute (should return a ResultSet)NoBodydataSourceDatabase connection to use (overrides the default)NoDefault databasemaxRowsMaximum number of results to store in the variableNoUnlimitedstartRowNumber of the row in the result at which to start recordingNo0varName of the variable to represent the databaseNoSet defaultscopeScope of variable to expose the result from the databaseNoPageExampleTo start with the basic concept, let us create an Employees table in the TEST database and create few records in that table as follows −Follow these steps ... Read More

Advertisements