Get Creation and Update Dates of Tables in MySQL

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

262 Views

Get the create and update tables exact date using the create_time or update_time in MySQL.At first, use the SHOW command. The syntax is as followsSHOW TABLE STATUS;We are considering our database ‘test3’, which is already having some tablesmysql> use test3; Database changedNow use the following query to display all the tables in the database test3mysql> show tables;The following is the output+-------------------------+ | Tables_in_test3         | +-------------------------+ | add6hour                | | deletedemo              | | differentdatetime       | | fieldlessthan5chars     | | ... Read More

LocalDate plusWeeks Method in Java

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

373 Views

An immutable copy of the LocalDate where the weeks are added to it can be obtained using the plusWeeks() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of weeks to be added and it returns the instant with the added weeks.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld1); ... Read More

LongStream.of() Method in Java

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

165 Views

The LongStream class in Java the following two forms of the of() method.The following of() method returns a sequential LongStream containing a single element. Here is the syntaxstatic LongStream of(long t)Here, parameter t is the single element.The following of() method returns a sequential ordered stream whose elements are the specified values.static LongStream of(long… values)Here, the parameter values are the elements of the new stream.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream of() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {   ... Read More

toString Method of Java AbstractCollection Class

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

340 Views

The toString() method of the AbstractCollection class is used to return the string representation of the elements of this collection.The syntax is as followspublic String toString()To work with AbstractCollection class in Java, import the following packageimport java.util.AbstractCollection;The following is an example to implement AbstractCollection toString() method in JavaExample Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("HDD");       absCollection.add("Earphone");       absCollection.add("Headphone");       absCollection.add("Card Reader");       absCollection.add("SSD");       absCollection.add("Pen Drive");       ... Read More

Trim Commas with MySQL

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

2K+ Views

The syntax is as follows to trim commas −SELECT TRIM(BOTH ', ' FROM yourColumnName) from yourTableName;Let us see an example −mysql> create table TrimCommasDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> AllTechnicalSkills text    -> ); Query OK, 0 rows affected (0.81 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into TrimCommasDemo(AllTechnicalSkills) values(', C, C++, Java, '); Query OK, 1 row affected (0.14 sec) mysql> insert into TrimCommasDemo(AllTechnicalSkills) values(', MySQL, SQL Server, MongoDB, '); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Increment MongoDB Value Inside a Nested Array

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

184 Views

To increment a value inside a nested array, use positional operator ($). Let us first create a collection with documents> db.incrementInNestedArrayDemo.insertOne( ... { ...    "StudentId":100, ...    "ProjectDetails": ...    [ ...       {"ProjectId":567778888, ...          "TeamSize":4 ...       }, ...       { ...          "ProjectId":67888999, ...          "TeamSize":2 ...       } ...    ] ... } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a6b7b15e86fd1496b38aa") }Following is the query to display all documents from a collection with the help ... Read More

Convert Integer ArrayList to Integer Array in Java

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

2K+ Views

To convert integer array list to integer array is not a tedious task. First, create an integer array list and add some elements to it −ArrayList < Integer > arrList = new ArrayList < Integer > (); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500);Now, assign each value of the integer array list to integer array. We used size() to get the size of the integer array list and placed the same size to the newly created integer array −final int[] arr = new int[arrList.size()]; int index = 0; for (final Integer value: arrList) {    arr[index++] = value; }Example Live Demoimport java.util.ArrayList; public ... Read More

Convert All Records in a MySQL Table from Uppercase to Lowercase

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

829 Views

Convert all the records in a MySQL table from uppercase to lowercase using UPDATE command along with LOWER() method.Let us first create a table −mysql> create table DemoTable    (    Id varchar(100),    StudentFirstName varchar(20),    StudentLastName varchar(20),    StudentCountryName varchar(10)    ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-101', 'John', 'Smith', 'US'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('STU-102', 'John', 'Doe', 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-103', 'David', 'Miller', 'AUS'); Query OK, 1 ... Read More

MongoDB Query to Remove Item from Array

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

259 Views

To remove item from array, you can use $pull operator. Let us create a collection with documents −> db.removeItemFromArray.insertOne(    { "_id":101, "StudentName":"Larry", "StudentSubjects":["C", "MongoDB", "Java", "MySQL"] } ); { "acknowledged" : true, "insertedId" : 101 }Display all documents from a collection with the help of find() method. The query is as follows −> db.removeItemFromArray.find().pretty();This will produce the following output −{    "_id" : 101,    "StudentName" : "Larry",    "StudentSubjects" : [       "C",       "MongoDB",       "Java",       "MySQL"    ] }Following is the query to remove item from an ... Read More

Search and Replace First Occurrence of Character in MySQL

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

302 Views

To perform search/ replace for only the first occurrence, use the CONCAT and REPLACE() function.The query is as follows to set user defined session variable −mysql> set @Sentence='Thks ks is a my string'; Query OK, 0 rows affected (0.00 sec)In this k will be replaced with i only once. The query is as follows. We have used INSTR() also −mysql> select @Sentence as NewString ,CONCAT(REPLACE(LEFT(@Sentence, INSTR(@Sentence, 'k')), 'k', 'i'),    -> SUBSTRING(@Sentence, INSTR(@Sentence, 'k') + 1)) as ChangeOnlyOneTime;The following is the output displaying only the first occurrence of a character is replaced −+------------------------+------------------------+ | NewString ... Read More

Advertisements