Create Table with Space in Name in MySQL

Nancy Den
Updated on 30-Jul-2019 22:30:25

4K+ Views

To create a table with a space in the table name in MySQL, you must use backticks otherwise you will get an error.Let us first see what error will arise by creating a table with a space in the name i.e. “Demo Table” table name below:mysql> create table Demo Table (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeFirstName varchar(20),    EmployeeLastName varchar(20),    EmployeeAge int,    EmployeeSalary int,    EmployeeAddress varchar(200) ); ERROR 1064 (42000): You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to ... Read More

Provider toString Method in Java

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

244 Views

The name and the version number of the provider in string form can be obtained using the method toString() in the class java.security.Provider. This method requires no parameters and it returns the name as well as the version number of the provider in string form.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("DSA");          Provider p = kpGenerator.getProvider();          System.out.println("The name and version number of ... Read More

Achieve Case-Sensitive Uniqueness and Case-Insensitive Search in MySQL

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

1K+ Views

You can achieve case sensitive uniqueness and case insensitive search with the help of the following two ways −VARBINARY data type_bin collationVARBINARY data typeTo work with the VARBINARY data type, let us first create a table. The query to create a table is as follows −mysql> create table SearchingDemo2 -> ( -> UserId VARBINARY(128) NOT NULL, -> UNIQUE KEY index_on_UserId2(UserId ) -> )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Query OK, 0 rows affected, 1 warning (0.99 sec)Keep in mind UserId has data type VARBINARY(128) and Index(‘index_on_UserId2’) on a column ‘UserId’._bin ... Read More

Set Title for Action Bar in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

5K+ Views

This example demonstrates How to set title for action bar 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 text view to show status bar tittle.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity ... Read More

Period withMonths Method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

197 Views

An immutable copy of a Period with the number of months as required is done using the method withMonths() in the Period class in Java. This method requires a single parameter i.e. the number of months in the Period and it returns the Period with the number of months as required.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

LocalTime toString Method in Java

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

946 Views

The string value of the LocalTime object can be obtained using the method toString() in the LocalTime class in Java. This method requires no parameters and it returns the string value of the LocalTime object.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt.toString());    } }OutputThe LocalTime is: 23:15:30Now let us understand the above program.The string value of the LocalTime is obtained using the method toString() and then this value ... Read More

MongoDB Query Condition on Comparing Two Fields

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

435 Views

To query condition on comparing 2 fields, use the following syntax −db.yourCollectionName.find( { $where: function() { return this.yourFirstFieldName < this.yourSecondFieldName } } ).pretty();To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.comparingTwoFieldsDemo.insertOne({"StudentName":"John", "StudentAge":21, "StudentMathMarks":99, "StudentPhysicsMarks":98}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ac09e6cea1f28b7aa0807") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentMathMarks":79, "StudentPhysicsMarks":89}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ac0b46cea1f28b7aa0808") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"David", "StudentAge":24, "StudentMathMarks":39, "StudentPhysicsMarks":45}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ac0c96cea1f28b7aa0809") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"Bob", "StudentAge":23, "StudentMathMarks":87, "StudentPhysicsMarks":78}); {    "acknowledged" : ... Read More

Convert Primitive Array to Stream in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

291 Views

To convert Primitive Array to Stream, you need to use the of() method.Let’s say the following is our Primitive Array:int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 };Now, use the of() method to convert the primitive array to stream:IntStream stream = IntStream.of(myArr);The following is an example to convert primitive array to stream in Java:Example Live Demoimport java.util.stream.IntStream; import java.util.*; public class Main {    public static void main(String[] args) {       int[] myArr = new int[] { 20, 50, 70, 90, 100, 120, 150 };       System.out.println("The Primitive Array = "+Arrays.toString(myArr));   ... Read More

MySQL Query to Display Databases Sorted by Creation Date

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

622 Views

You can display databases sorted by creation date with ORDER BY clause. Following is the query to display all databases −mysql> show databases;This will produce the following output −+---------------------------+ | Database                  | +---------------------------+ | bothinnodbandmyisam       | | business                  | | commandline               | | customer_tracker_database | | customertracker           | | database1                 | | databasesample            | | demo ... Read More

Loop Through Map by Map Entry in Java

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

230 Views

Create a Map and insert elements to in the form of key and value −HashMap map = new HashMap (); map.put("1", "A"); map.put("2", "B"); map.put("3", "C"); map.put("4", "D"); map.put("5", "E"); map.put("6", "F"); map.put("7", "G"); map.put("8", "H"); map.put("9", "I");Now, loop through Map by Map.Entry. Here, we have displayed the key and value separately −Sets = map.entrySet(); Iteratori = s.iterator(); while (i.hasNext()) {    Map.Entrye = (Map.Entry) i.next();    String key = (String) e.getKey();    String value = (String) e.getValue();    System.out.println("Key = "+key + " => Value = "+ value); }Example Live Demoimport java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; ... Read More

Advertisements