Access Subdocument Value When Key is a Number in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

169 Views

To access subdocument value, let us first create a collection with documents −> db.accessSubDocumentDemo.insertOne( ...    { ... ...       "Details" : { ...          "1" : { ...             "StudentLowerScore" : "33", ...             "StudentHoghScore" : "55" ...          }, ...          "2" : { ...             "StudentLowerScore" : "45", ...             "StudentHoghScore" : "65" ...          }, ...          "3" : ... Read More

Display All Titles of JTabbedPane Tabs on Console in Java

George John
Updated on 30-Jul-2019 22:30:26

491 Views

To display all the titles of the JTabbedPane, let us first get the count of tabs −int count = tabbedPane.getTabCount();Now, loop through the number of tabs in the JTabbedPane. Use the getTitleAt() to get the title of each and every tab −for (int i = 0; i < count; i++) {    String str = tabbedPane.getTitleAt(i);    System.out.println(str); }The following is an example to display all the titles of JTabbedPane tabs on Console −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Devices");     ... Read More

Set Grid Color of a Table in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

1K+ Views

To set the grid color of a table, use the setGridColor() method.table.setGridColor(Color.yellow);Above, we have used the Color class to set the color.The following is an example to set the grid color of a table −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JPanel panel = new JPanel();       panel.setBorder(BorderFactory.createTitledBorder(          BorderFactory.createEtchedBorder(), "ODI Rankings", TitledBorder.CENTER, TitledBorder.TOP));       String[][] rec = {       ... Read More

Rethrow an Exception in Java

raja
Updated on 30-Jul-2019 22:30:26

19K+ Views

Sometimes we may need to rethrow an exception in Java. If a catch block cannot handle the particular exception it has caught, we can rethrow the exception. The rethrow expression causes the originally thrown object to be rethrown.Because the exception has already been caught at the scope in which the rethrow expression occurs, it is rethrown out to the next enclosing try block. Therefore, it cannot be handled by catch blocks at the scope in which the rethrow expression occurred. Any catch blocks for the enclosing try block have an opportunity to catch the exception.Syntaxcatch(Exception e) {    System.out.println("An exception ... Read More

Remove Seconds from MySQL Datetime

Rama Giri
Updated on 30-Jul-2019 22:30:26

1K+ Views

To remove seconds from MySQL datetime, use UPDATE and SET as in the following syntax −update yourTableName set yourDateColumnName=yourDateColumnName -second(yourDateColumnName);Let us first create a table −mysql> create table DemoTable    -> (    -> Shippingdatetime datetime    -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-21 12:05:20'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('2019-03-01 10:23:35'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-06-09 11:00:56'); Query OK, 1 row affected (0.14 sec)Display all records from the table ... Read More

Problem in Many Binary Search Implementations

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

162 Views

We know that the binary search algorithm is better than the linear search algorithm. This algorithm takes O(log n) amount of time to execute. Though most of the cases the implemented code has some problem. Let us consider one binary search algorithm function like below −Exampleint binarySearch(int array[], int start, int end, int key){    if(start key)          return binarySearch(array, start, mid-1, key);          return binarySearch(array, mid+1, end, key);    }    return -1; }This algorithm will work fine until the start and end reaches a large number. If the (start + end) ... Read More

Any DataType in C++ Boost Library

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

275 Views

The boost library has large range of functionalities. The any datatype is one of them. Any datatype is used to store any type of values in variable. Some other languages like javascripts, python, we can get this kind of datatypes. In C++ we can get this feature only using boost library.Example#include "boost/any.hpp" #include using namespace std; main() {    boost::any x, y, z, a; //define some variable of any datatype    x = 20; //Store x as integer    cout >> "x : " >> boost::any_cast(x) >> endl; //display the value of x    y = 'A'; //Store y ... Read More

Static Keyword in C++ vs Java

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

696 Views

In C++ or Java we can get the static keyword. They are mostly same, but there are some basic differences between these two languages. Let us see the differences between static in C++ and static in Java.The static data members are basically same in Java and C++. The static data members are the property of the class, and it is shared to all of the objects.Examplepublic class Test {    static int ob_count = 0;    Test() {       ob_count++;    }    public static void main(String[] args) {       Test object1 = new Test();   ... Read More

SQL Insert Items from List or Collection into Table using JDBC

Rishi Raj
Updated on 30-Jul-2019 22:30:26

6K+ Views

To insert the contents of a database to a collection, Connect to the database and retrieve the contents of the table into a ResultSet object using the SELECT Query.DriverManager.registerDriver(new com.mysql.jdbc.Driver()); String mysqlUrl = "jdbc:mysql://localhost/mydatabase"; Connection con = DriverManager.getConnection(mysqlUrl, "root", "password"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from MyPlayers");Create a Java class to hold the contents of each record, with a variable and, setter and getter methods for each column (with suitable datatype).For example, if the table sample in the database has two fields with the details −Column name: ID, datatype: INT(11)Column name: Name, datatype VARCHAR(255)Then, the variable ... Read More

Insert 8-Byte Integer into MongoDB using JavaScript Shell

Anvi Jain
Updated on 30-Jul-2019 22:30:26

246 Views

You can use below syntax for inserting an 8-byte integer in MongoDB through JavaScript shell −anyVariableName= {"yourFieldName" : new NumberLong("yourValue")};To display the above variable, you can use the variable name or printjson(). Following is the query to insert 8 byte integer in MongoDB −> userDetail = {"userId" : new NumberLong("98686869")}; { "userId" : NumberLong(98686869) }Let us display the above variable value using variable name. The query is as follows −> userDetailThis will produce the following output −{ "userId" : NumberLong(98686869) }Let us display the variable value using printjson() −> printjson(userDetail); This will produce the following output −{ "userId" : NumberLong(98686869) }

Advertisements