Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 66 of 81

Generate Infinite Stream of Double in Java using DoubleStream.iterate()

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 152 Views

The DoubleStream.iterate() returns an infinite sequential ordered DoubleStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed.The syntax is as followsstatic DoubleStream iterate(double seed, DoubleUnaryOperator f)Here, seed is the initial element and f is a function to be applied to the previous element to produce a new element.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to generate infinite stream of Double in Java with DoubleStream.iterate()Exampleimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { ...

Read More

Is it possible to enforce data checking in MySQL using Regular Expression?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 387 Views

Yes, it is possible to enforce data checking in MySQL using regular expression. First, you need to create a table. After that you need to create a trigger before insert in table. Here, we will be checking the Phone Number format.The query to create a table is as followsmysql> create table enforceDataUsingRegularExpression - > ( - > yourPhoneNumber varchar(60) - > ); Query OK, 0 rows affected (0.59 sec)The query to create a trigger is as followsmysql> DELIMITER // mysql> CREATE TRIGGER enforce_phone_check BEFORE INSERT ON enforceDataUsingRegularExpression - ...

Read More

Drop all indexes from all the collections in a MongoDB database using the command line?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 298 Views

Following is the syntax to drop all indexes from all collections in a MongoDB database using command linedb.getCollectionNames().forEach(function(yourVariableName) {    db.runCommand({dropIndexes: yourVariableName, index: "*"}); });The above syntax will drop all indexes except _id.Let us check the current database. Following is the query> dbThis will produce the following outputTestFollowing is the query to let us show some indexes from a collection before dropping indexes> db.indexingDemo.getIndexes();This will produce the following output[    {       "v" : 2,       "key" : {          "_id" : 1       },       "name" : "_id_", ...

Read More

Access objects from the nested objects structure in MongoDB

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 761 Views

Access objects using dot notation. Let us first create a collection with documents> db.nestedObjectDemo.insertOne({"Student" : { "StudentDetails" : { "StudentPersonalDetails" : { "StudentName" : [ "John" ], ... "StudentCountryName" : [ "US" ], ... "StudentCoreSubject" : [ "C", "Java" ], ... "StudentProject" : [ "Online Book Store", "Pig Dice Game" ] } } } }); {    "acknowledged" : true,    "insertedId" : ObjectId("5c99dfc2863d6ffd454bb650") }Following is the query to display all documents from a collection with the help of find() method> db.nestedObjectDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c99dfc2863d6ffd454bb650"),    "Student" : {       "StudentDetails" : ...

Read More

Get only the file extension from a column with file names as strings in MySQL?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 1K+ Views

For this, use the substring_index() function.The syntax is as followsselect substring_index(yourColumnName, '. ', -1) AS anyAliasNamefrom yourTableName;Let us first create a table. The query to create a table is as followsmysql> create table AllFiles - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > UserName varchar(10), - > FileName varchar(100) - > ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into AllFiles(UserName, FileName) values('Larry', 'AddTwoNumber.java'); Query OK, 1 ...

Read More

How to get default phone Network operator name in android?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 1K+ Views

This example demonstrate about How to get default phone Network operator name 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 a text view to show the phone network operator name.Step 3 − Add the following code to java/MainActivity.xmlpackage com.example.myapplication; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.widget.TextView; ...

Read More

Query MongoDB with length criteria?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 220 Views

To query MongoDB with length criteria, you can use regex. Following is the syntaxdb.yourCollectionName.find({ ‘yourFieldName’: { $regex: /^.{yourLengthValue1, yourLengthValue2}$/ } });Let us create a collection with documents. Following is the query> db.queryLengthDemo.insertOne({"StudentFullName":"John Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01ae353decbc2fc927c0") } > db.queryLengthDemo.insertOne({"StudentFullName":"John Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01b4353decbc2fc927c1") } > db.queryLengthDemo.insertOne({"StudentFullName":"David Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01c2353decbc2fc927c2") } > db.queryLengthDemo.insertOne({"StudentFullName":"Robert Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01e2353decbc2fc927c3") } > db.queryLengthDemo.insertOne({"StudentFullName":"Chris Williams"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01f1353decbc2fc927c4") }Following is the query to display ...

Read More

How to find the previous and next record using a single query in MySQL?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 7K+ Views

You can use UNION to get the previous and next record in MySQL.The syntax is as follows(select *from yourTableName WHERE yourIdColumnName > yourValue ORDER BY yourIdColumnName ASC LIMIT 1) UNION (select *from yourTableName WHERE yourIdColumnName < yourValue ORDER BY yourIdColumnName DESC LIMIT 1);To understand the concept, let us create a table. The query to create a table is as followsmysql> create table previousAndNextRecordDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Name varchar(30) - > ); Query OK, 0 rows affected (1.04 ...

Read More

Only insert if a value is unique in MongoDB else update

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 816 Views

You can use upsert i.e. whenever you insert a value and it already exist then update would be performed. If the value does not already exist then it would get inserted.Let us first create a collection with documents> db.onlyInsertIfValueIsUniqueDemo.insertOne({"StudentName":"Larry", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a633815e86fd1496b38a4") } > db.onlyInsertIfValueIsUniqueDemo.insertOne({"StudentName":"Mike", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a634a15e86fd1496b38a5") } > db.onlyInsertIfValueIsUniqueDemo.insertOne({"StudentName":"Sam", "StudentAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a635015e86fd1496b38a6") }Following is the query to display all documents from a collection with the help of find() method> db.onlyInsertIfValueIsUniqueDemo.find().pretty();This will produce the following output{    "_id" ...

Read More

Does MySQL have an expanded output flag similar PostgreSQL?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 181 Views

Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as followsSELECT *FROM yourTableName\GLet us first create a table as an examplemysql> create table expandedOutputDemo    - > (    - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > EmployeeName varchar(20),    - > EmployeeAge int    - > ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Larry', 27); Query OK, 1 row affected (0.16 sec) mysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Mike', 29); Query ...

Read More
Showing 651–660 of 810 articles
« Prev 1 64 65 66 67 68 81 Next »
Advertisements