Use MongoDB Field Value as Pattern in Regex

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

204 Views

Yes, for this, use $indexOfCP operator along with aggregate framework. Let us first create a collection with documents −> db.patterDemo.insertOne(    {       "ClientName": "John", "ClientWebsiteName":"webbuziness.com/John/business"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea40acef71edecf6a1f68d") } > db.patterDemo.insertOne(    {       "ClientName": "Carol", "ClientWebsiteName":"solvecoding.com/business"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea40acef71edecf6a1f68e") }Following is the query to display all documents from a collection with the help of find() method −> db.patterDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cea40acef71edecf6a1f68d"),    "ClientName" : "John",    "ClientWebsiteName" : "abcd.com" ... Read More

C Program to Find the Area of a Circle

Sharon Christine
Updated on 30-Jul-2019 22:30:26

17K+ Views

The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two dimensional plane.To find the area of a circle, the radius[r] or diameter[d](2* radius) is required.The formula used to calculate the area is (π*r2) or {(π*d2)/4}.Example CodeTo find the area of a circle using radius. Live Demo#include int main(void) {    float pie = 3.14;    int radius = 6;    printf("The radius of the circle is %d " , radius);    float area = (float)(pie* radius * radius);    printf("The ... Read More

Get Total Number of Rows in a MySQL Database

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

4K+ Views

To get the total number of rows in a MySQL database, you can use aggregate function SUM() along with inbuilt column TABLE_ROWS from INFORMATION_SCHEMA.TABLES.The syntax is as follows−SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();Let’s say we are using the database with the name ‘sample’.Now we will get the total number of rows in a MySQL database−mysql> SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();This will produce the following output−+-----------------+ | SUM(TABLE_ROWS) | +-----------------+ | 2043 | +-----------------+ 1 row in set (22.11 sec)

Get Default Transaction Isolation using DatabaseMetaData in Java

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

195 Views

In a database system where more than one transaction is being executed simultaneously and in parallel, the property of isolation states that all the transactions will be carried out and executed as if it is the only transaction in the system. No transaction will affect the existence of any other transaction.The getDefaultTransactionIsolation() method of the DatabaseMetaData interface returns the default isolation level of the underlying database in integer format.To know the default transaction isolation of the underlying database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of ... Read More

Store Time Created in a MySQL Table

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

220 Views

You can use DEFAULT CURRENT_TIMESTAMP. Keep in mind that it will work only at the time of insertion. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Arrivaltime TIMESTAMP DEFAULT CURRENT_TIMESTAMP    ); Query OK, 0 rows affected (0.31 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Arrivaltime) values('2018-01-31 10:34:56'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Arrivaltime) values('2019-01-31 11:10:12'); Query OK, 1 row affected (0.04 sec)Display ... Read More

Add Scrollbar to JList in Java

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

5K+ Views

Let us first set a JList and add items −List myList = new ArrayList(10); for (int index = 0; index < 20; index++) {    myList.add("List Item " + index); }Now, we will set the above list to a new list −final JList list = new JList(myList.toArray(new String[myList.size()]));Now, set the ScrollBar to JList −JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(list); list.setLayoutOrientation(JList.VERTICAL);The following is an example to add ScrollBar to JList −Examplepackage my; import java.awt.BorderLayout; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String[] args) {       JPanel ... Read More

Replace an Array Field Value with MongoDB

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

331 Views

You can use positional operator $. Let us first create a collection with documents −> db.replaceAnArrayFieldValueDemo.insertOne({"StudentTechnicalSubjects":["MySQL", "SQL Server", "PL/SQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea41e0ef71edecf6a1f68f") }Following is the query to display all documents from a collection with the help of find() method −> db.replaceAnArrayFieldValueDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cea41e0ef71edecf6a1f68f"),    "StudentTechnicalSubjects" : [       "MySQL",       "SQL Server",       "PL/SQL"    ] }Following is the query to replace an array field value. Here, we are updating “SQL Server” with “MongoDB” −> db.replaceAnArrayFieldValueDemo.update(    {"StudentTechnicalSubjects":"SQL Server"},   ... Read More

What is Narrowing in Java? Explained

Venkata Sai
Updated on 30-Jul-2019 22:30:26

5K+ Views

Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) as listed below −boolean − Stores 1-bit value representing true or, false.byte − Stores twos compliment integer up to 8 bits.char − Stores a Unicode character value up to 16 bits.short − Stores an integer value upto 16 bits.int − Stores an integer value upto 32 bits.long − Stores an integer value upto 64 bits.float − Stores a floating point value upto 32bits.double − Stores a floating point value up to 64 bits.Converting one primitive data type into another is known as type ... Read More

MySQL Query to Find Rows with Strings Less Than Four Characters

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

381 Views

Use CHAR_LENGTH() and find the count of characters in every string and then get the strings which are less than four characters. Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (1.38 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (1.60 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.25 ... Read More

Add Two Integers in C

Sharon Christine
Updated on 30-Jul-2019 22:30:26

1K+ Views

A program to add two numbers takes to numbers and does their mathematical sum and gives it to another variable that stores its sum.Example Code Live Demo#include int main(void) {    int a = 545;    int b = 123;    printf("The first number is %d and the second number is %d ", a , b);    int sum = a + b;    printf("The sum of two numbers is %d" , sum);    return 0; }OutputThe first number is 545 and the second number is 123 The sum of two numbers is 668

Advertisements