Remove Hyphens Using MySQL UPDATE

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

922 Views

To remove hyphens using MySQL update, you can use replace() function. The syntax is as follows −update yourTableName    set yourColumnName=replace(yourColumnName, '-', '' );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeHyphensDemo    -> (    -> userId varchar(100)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into removeHyphensDemo values('John-123-456'); Query OK, 1 row affected (0.22 sec) mysql> insert into removeHyphensDemo values('Carol-9999-7777-66555'); Query OK, 1 row affected (0.19 sec) ... Read More

Add Not Null Constraint to a Column in Database Using JDBC API

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

411 Views

You can add a not null constraint to a column of a table using the ALTER TABLE command.SyntaxALTER TABLE table_name MODIFY column_name datatype NOT NULL;Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL    |       | | CustomerName | varchar(255) | YES  |     | NULL   ... Read More

Upsert in MongoDB with Custom ID Values

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

614 Views

You need to use insert() for this. Whenever you insert custom _id values and the document already exist with the custom _id value then an error is visible. Let us first create a collection with documents. Under this, we tried adding the same document again and this resulted in an error> db.customIdDemo.insert({"_id":1, "StudentName":"John"}); WriteResult({ "nInserted" : 1 }) > db.customIdDemo.insert({"_id":1, "StudentName":"Carol"}); WriteResult({    "nInserted" : 0,    "writeError" : {       "code" : 11000,       "errmsg" : "E11000 duplicate key error collection: admin.customIdDemo index: _id_ dup key: { : 1.0 }"    } }) > db.customIdDemo.insert({"_id":2, "StudentName":"Carol"}); ... Read More

C++ Program to Perform Edge Coloring of a Graph

Paul Richard
Updated on 30-Jul-2019 22:30:25

654 Views

In this program, we will perform Edge Coloring of a Graph in which we have to color the edges of the graph that no two adjacent edges have the same color. Steps in Example.AlgorithmBegin    Take the input of the number of vertices, n, and then number of edges, e, in the graph.    The graph is stored as adjacency list.    BFS is implemented using queue and colors are assigned to each edge. EndExample#include using namespace std; int n, e, i, j; vector g; vector color; bool v[111001]; void col(int n) {    queue q;    int c = ... Read More

Get the Count of Documents in a MongoDB Collection

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

234 Views

To get the count of the number of documents in a collection MongoDB, you can use the below syntax −db.getCollectionNames().map(function(anyVariableName) {    return { "yourVariableName": yourVariableName, "count": db[yourVariableName].count() } });Here, we are using ‘test’ database.Let us implement the above syntax to get the count of the number of documents in a MongoDB collection −> db.getCollectionNames().map(function(ColName) { ... return { "ColName": ColName, "TotalDocument": db[ColName].count() } ... });This will produce the following output −[    {       "ColName" : "ConvertStringToDateDemo",       "TotalDocument" : 4    },    {       "ColName" : "Employee_Information",       "TotalDocument" ... Read More

MySQL New User Access Denied Even After Giving Privileges

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

390 Views

After creating a user and giving all privileges to the user, you need to FLUSH PRIVILEGES to set up and want the new settings to work correctly.The syntax is as follows −FLUSH PRIVILEGES;Here is the query to create a new user which has the name ‘Bob’ in my case. The query to create a new user is as follows −mysql> CREATE USER 'Bob'@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.56 sec)Now given all privileges to user Bob −mysql> GRANT ALL PRIVILEGES ON *.* TO 'Bob'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.23 sec)Now flush the privileges. ... Read More

ByteBuffer get() Method in Java

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

482 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.ByteBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ByteBuffer buffer = ByteBuffer.allocate(n); ... Read More

Duration minusSeconds Method in Java

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

157 Views

An immutable copy of a duration where some seconds are removed from it can be obtained using the minusSeconds() method in the Duration class in Java. This method requires a single parameter i.e. the number of seconds to be subtracted and it returns the duration with the subtracted seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofMinutes(1); System.out.println("The duration is: " + d); ... Read More

Count Two Different Columns in a Single Query in MySQL

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

5K+ Views

You can use CASE statement to count two different columns in a single query. To understand the concept, let us first create a table. The query to create a table is as follows.mysql> create table CountDifferentDemo    - > (    - > ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > ProductName varchar(20),    - > ProductColor varchar(20),    - > ProductDescription varchar(20)    - > ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountDifferentDemo(ProductName, ProductColor, ProductDescription) values('Product-1', 'Red', 'Used'); Query OK, 1 row ... Read More

Get Default Phone Network Country ISO in Android

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

565 Views

This example demonstrate about How to get default phone Network Country Iso 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 phone country iso.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; import static ... Read More

Advertisements