Krantik Chavan has Published 278 Articles

How to update a range of records in MySQL?

Krantik Chavan

Krantik Chavan

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

874 Views

To update a range of records in MySQL, you can use BETWEEN. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Age int ); Query OK, 0 rows affected (0.53 sec)Following is the query to insert some ... Read More

MonthDay isSupported() Method in Java

Krantik Chavan

Krantik Chavan

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

117 Views

It can be checked if a ChronoField is supported by the MonthDay class or not by using the isSupported() method in the MonthDay class in Java. This method requires a single parameter i.e. the ChronoField to check. It returns true if the ChronoField is supported by the MonthDay class and ... Read More

Java Program to convert HashSet to Enumeration

Krantik Chavan

Krantik Chavan

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

236 Views

Let’s say the following is our HashSet:HashSet set = new HashSet(); set.add("P"); set.add("Q"); set.add("R"); set.add("S"); set.add("T"); set.add("U"); set.add("V"); set.add("W"); set.add("X"); set.add("Z");Now convert the above HashSet to Enumeration:Enumeration enumeration = Collections.enumeration(set); while (enumeration.hasMoreElements())    System.out.println(enumeration.nextElement());Exampleimport java.util.Collections; import java.util.Enumeration; import java.util.HashSet; public class Demo {    public static void main(String[] args) ... Read More

Can we ignore duplicate rows in COUNT?

Krantik Chavan

Krantik Chavan

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

5K+ Views

Yes, we can ignore duplicate rows in COUNT using DISTINCT. Following is the syntax:select count(distinct yourColumnName) from yourTableName;In MySQL, COUNT() will display the number of rows. DISTINCT is used to ignore duplicate rows and get the count of only unique rows.Let us first create a table:mysql> create table DemoTable ( ... Read More

MonthDay isValidYear() Method in Java

Krantik Chavan

Krantik Chavan

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

95 Views

It can be checked if a year is valid or not for a MonthDay object using the isValidYear() method in the MonthDay class in Java. This method requires a single parameter i.e. the year which is to be checked. Also, it returns true if the year is valid for a ... Read More

Java Program to convert Instant to LocalDateTime

Krantik Chavan

Krantik Chavan

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

557 Views

Let’s say you need to convert Instant to LocalDateTime with IST with timezone:Create an Instant:Instant instant = new Date().toInstant();Now, convert Instant to LocalDateTime:LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("IST")));Exampleimport java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Instant instant ... Read More

Change the file extension in the text column in MySQL?

Krantik Chavan

Krantik Chavan

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

448 Views

To change the file extension in the text column, you can use UPDATE command along with REPLACE() function. Let’s say we have some columns with extensions and we need to replace all of them. For that, let us first create a table with the extension columns set as text type:mysql ... Read More

Display a TreeSet in reverse order in Java

Krantik Chavan

Krantik Chavan

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

400 Views

To display a TreeSet in reverse order, you need to use Comparator. Let us first create an Integer array and use it for the TreeSet elements:Integer arr[] = { 25, 100, 125, 200, 250, 400, 450, 550, 600, 700};Now, use reverseOrde() comparator to reverse the natural ordering:Set set = new ... Read More

Get records in a certain order using MySQL?

Krantik Chavan

Krantik Chavan

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

125 Views

You can use ORDER BY IF() to get records in a certain order. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20),    Branch varchar(20) ); Query OK, 0 rows affected (1.96 sec)Following is the query to insert ... Read More

Java Program to get headset from TreeSet

Krantik Chavan

Krantik Chavan

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

128 Views

To get HeadSet from TreeSet, at first create a TreeSet and add some elements:TreeSet treeSet = new TreeSet(); treeSet.add("ABC"); treeSet.add("DEF"); treeSet.add("GHI"); treeSet.add("JKL"); treeSet.add("MNO"); treeSet.add("PQR");To get headset, use the headset() method:SortedSet set = treeSet.headSet("MNO"); System.out.println("Head Set = " + set);You can also change the value like this:set = treeSet.headSet("GHI"); System.out.println("Head Set ... Read More

Advertisements