George John has Published 1167 Articles

Storing money amounts in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

7K+ Views

To store money amounts in MySQL, the best choice is to use DECIMAL data type or NUMERIC type. Float data type is not a good choice for money amounts. It gives some rounding errors. Therefore, avoid float for money amounts.Let us first create a table with data type DECIMAL. The ... Read More

Calculate age based on date of birth in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

11K+ Views

Calculate Age based on date of birth with the help of DATE_FORMAT() method in MySQL. Firstly, get the current date time with the help of now() method and you can place your date of birth in DATE_FORMAT().The syntax is as follows −SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(now(), 'yourDateofbirth')), '%Y')+0 AS anyVariableName;Apply the above syntax ... Read More

MySQL Server port number?

George John

George John

Updated on 30-Jul-2019 22:30:24

695 Views

If you will install MySQL on your system, then you will get the default MySQL server port number i.e. 3306.To know the MySQL server port number, you can use the following query. Here, we have used the SHOW VARIABLES command. The query is as follows −mysql> SHOW VARIABLES WHERE Variable_Name ... Read More

Convert DateTime Value into String in MySQL?

George John

George John

Updated on 30-Jul-2019 22:30:24

2K+ Views

To convert the DateTime value into string in MySQL, you can use the DATE_FORMAT() function. The syntax is as follows −select date_format(yourColumnName, ‘%d %m %y’) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table ... Read More

NavigableSet Class ceiling() method in Java

George John

George John

Updated on 30-Jul-2019 22:30:24

103 Views

The ceiling() method returns the least element greater than or equal to the given element i.e. 30 hereceiling(30)The following is an example to implement the ceiling method in JavaExample Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo { public static void main(String[] args) { ... Read More

MySQL - CAST DECIMAL to INT?

George John

George John

Updated on 30-Jul-2019 22:30:24

4K+ Views

Cast DECIMAL to INT with the help of FLOOR() function. The syntax is as follows −SELECT FLOOR(yourColumnName) from yourTableName where condition;Let us first create a table. The following is the query to create a table.mysql> create table DecimalToIntDemo -> ( -> Amount DECIMAL(3, 1) ... Read More

Java Program to retrieve the set of all keys in HashMap

George John

George John

Updated on 30-Jul-2019 22:30:24

224 Views

First, create a HashMap and add elementsHashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, retrieve all the keysSet keys = hm.keySet(); System.out.println("Keys..."); Iterator i = keys.iterator(); while (i.hasNext()) {    System.out.println(i.next()); }The following is an example to get the set of all key in ... Read More

What is Polynomial Code?

George John

George John

Updated on 30-Jul-2019 22:30:24

3K+ Views

A polynomial code is a linear code having a set of valid code words that comprises of polynomials divisible by a shorter fixed polynomial is known as generator polynomial.They are used for error detection and correction during the transmission of data as well as storage of data.Types of Polynomial CodesThe ... Read More

In MySQL how to replace all NULL values in a particular field of a particular table?

George John

George John

Updated on 30-Jul-2019 22:30:24

214 Views

To replace all NULL values in a particular field of a particular table, use UPDATE command with IS NULL property. The syntax is as follows:UPDATE yourTableName SET yourColumnName=”yourValue’ WHERE yourColumnName IS NULL;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> ... Read More

Why we mention in MySQL WHERE 1=0?

George John

George John

Updated on 30-Jul-2019 22:30:24

4K+ Views

The condition 1=0 can be used to stop the query from returning any rows. It returns empty set.The syntax is as follows:SELECT *FROM yourTableName WHERE 1=0;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table ConditionDemo    -> ( ... Read More

Advertisements