Get Field Name Types from a MySQL Database

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

344 Views

You can use INFORMATION_SCHEMA.COLUMNS for this. Following is the syntax −SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='yourTableName';Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(60),    ClientAge int,    ClientSalary DECIMAL(10, 4),    isRegularClient bool    ); Query OK, 0 rows affected (0.44 sec)Following is the query to get field name types from a SQL database −mysql> SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='DemoTable';This will produce the following output −+-----------------+---------------+ | COLUMN_NAME | COLUMN_TYPE | +-----------------+---------------+ | Id ... Read More

Generate Randomized Sequence of Given Range of Numbers in C++

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

544 Views

At first let us discuss about the rand() function. rand() function is a predefined method of C++. It is declared in header file. rand() is used to generate random number within a range. Here min_n is the minimum range of the random numbers and max_n is the maximum range of the numbers. So rand() will return the random numbers between min_n to (max_n – 1) inclusive of the limit values. Here if we mention lower and upper limits as 1 and 100 respectively, then rand() will return values from 1 to (100 – 1). i.e. from 1 to 99.AlgorithmBegin ... Read More

Select Part of a Timestamp in a MySQL Query

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

184 Views

To select part of a timestamp in a query, you need to use YEAR() function. The syntax is as follows in MySQL.select YEAR(yourTimestampColumnName) as anyAliasName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SelectPartOfTimestampDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingTime TIMESTAMP -> ); Query OK, 0 rows affected (1.11 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> ... Read More

What is a Unit Class in JavaTuples

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

410 Views

A Unit class is a Tuple of one element. It is in the JavaTuples library.The following is the declaration −public final class Unit extends Tuple implements IValue0Let us first see what we need to work with JavaTuples. To work with Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Some of its features include −TypesafeSerializableComparableIterableImmutableLet us see an example to create Unit Tuple in Java −Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the ... Read More

Use Trim in Android SQLite

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

388 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use trim () in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Best Way to Change Date Format in MySQL SELECT

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

1K+ Views

The best way to change the date format in MySQL SELECT is as followsSELECT DATE_FORMAT(yourColumnName, "%d/%m/%Y %H:%i") AS anyAliasName FROM yourTableName WHERE yourCondition;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table bestDateFormatDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > ArrivalDateTime datetime - > ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into bestDateFormatDemo(ArrivalDateTime) values(now()); Query OK, ... Read More

LocalDate minusDays Method in Java

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

250 Views

An immutable copy of the LocalDate where the days are subtracted from it can be obtained using the minusDays() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of days to be subtracted and it returns the instant with the subtracted days.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

Instant AtZone Method in Java

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

158 Views

An Instant can be combined with a timezone to create a ZonedDateTime object using the atZone() method in the Instant class in Java. This method requires a single parameter i.e. the ZoneID and it returns the ZonedDateTime object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Instant i = Instant.parse("2019-01-13T18:35:19.00Z");       System.out.println("The Instant object is: " + i);       ZonedDateTime zdt = i.atZone(ZoneId.of("Australia/Melbourne"));       System.out.println("The ZonedDateTime object is: " + zdt);    } }OutputThe Instant object is: 2019-01-13T18:35:19Z ... Read More

Pull and Add to Set at the Same Time with MongoDB

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

824 Views

Yes, you can use pull and add at the same time with $addToSet and $pull operator. Let us first create a collection with documents> db.pullAndAddToSetDemo.insertOne({StudentScores : [78, 89, 90]} ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a797e15e86fd1496b38af") }Following is the query to display all documents from a collection with the help of find() method> db.pullAndAddToSetDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9a797e15e86fd1496b38af"),    "StudentScores" : [       78,       89,       90    ] }Following is the query to pull and addtoset at the same time in MongoDB> var ... Read More

Check if a Table Exists in MySQL and Create if Not

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

1K+ Views

If you try to create a table and the table name already exist then MySQL will give a warning message. Let us verify the concept.Here, we are creating a table that already exist −mysql> CREATE TABLE IF NOT EXISTS DemoTable    (    CustomerId int,    CustomerName varchar(30),    CustomerAge int    ); Query OK, 0 rows affected, 1 warning (0.05 sec)The table name DemoTable is already present. Let us check the warning message.Following is the query −mysql> show warnings;This will produce the following output i.e. the warning message −+-------+------+------------------------------------+ | Level | Code | Message ... Read More

Advertisements