To delete cookies is very simple. If you want to delete a cookie, then you simply need to follow these three steps −Read an already existing cookie and store it in Cookie object.Set cookie age as zero using the setMaxAge() method to delete an existing cookie.Add this cookie back into the response header.Following example will show you how to delete an existing cookie named "first_name" and when you run main.jsp JSP next time, it will return null value for first_name.Example Live Demo Reading Cookies ... Read More
This example demonstrate about How to use split () in Android textview.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 as Edit text, when user click on button it will take data and split the data using space regex.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import ... Read More
To set value in the JavaTuples KeyValue class, you need to use the setValue() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuplesSteps: How to run JavaTuples program in EclipseThe following is an example to set ... Read More
You can use $facet operator for this. To understand the concept, let us create a collection with document. The query to create a collection with document is as follows −> db.totalDocumentDemo.insertOne({"InstructorId":100, "InstructorName":"Larry", "InstructorFav ouriteSubject":["Java", "MongoDB", "Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e6701e9c5dd6f1f78274") } > db.totalDocumentDemo.insertOne({"InstructorId":200, "InstructorName":"Sam", "InstructorFav ouriteSubject":["SQL Server", "C#", "Javascript"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76e69c1e9c5dd6f1f78275") }Display all documents from a collection with the help of find() method. The query is as follows −> db.totalDocumentDemo.find().pretty();Output{ "_id" : ObjectId("5c76e6701e9c5dd6f1f78274"), "InstructorId" : 100, "InstructorName" : "Larry", "InstructorFavouriteSubject" : [ ... Read More
To find the largest document size in MongoDB, you need to write a script in the shell.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.largestDocumentDemo.insertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed2e32f684a30fbdfd57d") } > db.largestDocumentDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentCountryName":"US", "TechnicalSubject":["C", "C++", "Java", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3282f684a30fbdfd57e") } > db.largestDocumentDemo.insertOne({"StudentName":"Mike", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed3382f684a30fbdfd57f") }Display all documents from a collection with the help of find() method. The query is as follows −> ... Read More
The valueOf() method of the Date object accepts a String value representing a Date in JDBC escape format i.e. yyyy-mm-dd and converts the given String value into java.sql.Date object.Date date = Date.valueOf(“date_string”);Assume we have created a table named employee_data with the description as shown below:+----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | Name | varchar(255) | YES | ... Read More
It is not possible to return only embedded document. However, it will return all the documents from a collection. Let us first implement the following query to create a collection with documents>db.queryToEmbeddedDocument.insertOne({"UserName":"Larry", "PostDetails":[{"UserMessage":"Hello", "UserLikes":8}, {"UserMessage":"Hi", "UserLikes":6}, {"UserMessage":"Good Morning", "UserLikes":12}, {"UserMessage":"Awesome", "UserLikes":4}]}); { "acknowledged" : true, "insertedId" : ObjectId("5c988a9f330fd0aa0d2fe4bd") }Following is the query to display all documents from a collection with the help of find() method> db.queryToEmbeddedDocument.find().pretty();This will produce the following output{ "_id" : ObjectId("5c988a9f330fd0aa0d2fe4bd"), "UserName" : "Larry", "PostDetails" : [ { "UserMessage" : "Hello", ... Read More
The variable declaration must be between BEGIN and END. Under BEGIN and END, the first statement must be declaration of variable. After that you can include insert, select, etc.Let us now see an example. Here, the variable name is “output”:mysql> DELIMITER // mysql> CREATE PROCEDURE showVariablesValue() -> BEGIN -> DECLARE output varchar(100); -> SET output="Hello MySQL"; -> SELECT output; -> END -> // Query OK, 0 rows affected (0.25 sec) mysql> DELIMITER ;Now you can call the stored procedure using call ... Read More
For random numbers in Java, create a Random class object −Random randNum = new Random();Now, create a HashSet to get only the unique elements i.e. no duplicates −Setset = new LinkedHashSet();Generate random numbers with Random class nextInt −while (set.size() < 5) { set.add(randNum.nextInt(5)+1); }Exampleimport java.util.LinkedHashSet; import java.util.Random; import java.util.Set; public class Demo { public static void main(final String[] args) throws Exception { Random randNum = new Random(); Setset = new LinkedHashSet(); while (set.size() < 5) { set.add(randNum.nextInt(5)+1); } System.out.println("Random numbers with no duplicates = "+set); } }OutputRandom numbers with no duplicates = [2, 4, 1, 3, 5]
This is a C++ Program to Generate N Number of Passwords of Length M Each.AlgorithmBegin Take the length of password as input. function permutation() generate random passwords: /* Arguments A pointer array a. Total Number of random numbers m. Length of the password s. */ // Body of the function: if (m == s) for i = 0 to s-1 Print *(a + i) else for i = m to s-1 ... Read More