Samual Sam has Published 2492 Articles

How do I discover the Quarter of a given Date in Java?

Samual Sam

Samual Sam

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

2K+ Views

Let us first get the current date −LocalDate currentDate = LocalDate.now();Now, use the Calendar class and set the locale −Calendar cal = Calendar.getInstance(Locale.US);Now, get the month −int month = cal.get(Calendar.MONTH);Find the Quarter −int quarter = (month / 3) + 1;Exampleimport java.time.LocalDate; import java.util.Calendar; import java.util.Locale; public class Demo {   ... Read More

Remove null element from MongoDB array?

Samual Sam

Samual Sam

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

877 Views

You can use $pull operator for this. Let us first create a collection with documents −> db.removeNullDemo.insertOne( ... { ...    "_id" : 1, ...    "StudentDetails" : [ ...       { ...          "FirstName": "John", ...          "LastName":"Smith", ... ...   ... Read More

What are cookies in JSP?

Samual Sam

Samual Sam

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

238 Views

Cookies are text files stored on the client computer and they are kept for various information tracking purposes. JSP transparently supports HTTP cookies using underlying servlet technology.There are three steps involved in identifying and returning users -Server script sends a set of cookies to the browser. For example, name, age, ... Read More

Format date in MySQL SELECT * query uisng FORMATDATE() method?

Samual Sam

Samual Sam

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

90 Views

Use the DATE_FORMAT(), not FORMATDATE() in MySQL to format date. The correct syntax is as follows −SE LECT *, DATE_FORMAT(yourDateCoumnName, ’yourFormat’) as anyAliasName FROM yourTableNameTo understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateFormatDemo    -> ( ... Read More

Clock systemDefaultZone() Method in Java

Samual Sam

Samual Sam

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

78 Views

The current instance of the clock with the default time zone can be obtained using the method systemDefaultZone() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the default time zone.A program that demonstrates this is given as ... Read More

Java Program to convert java.util.Date to any local date in certain timezone

Samual Sam

Samual Sam

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

128 Views

First, set the Date and ZoneId −Date date = new Date(); ZoneId zone = ZoneId.systemDefault();Now convert the java.util.date to localdate −date.toInstant().atZone(zone).toLocalDate() date.toInstant().atZone(zone).toLocalTime() date.toInstant().atZone(zone).getHour() date.toInstant().atZone(zone).getMinute() date.toInstant().atZone(zone).getSecond()Exampleimport java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Date date = new Date();       ... Read More

How do you set cookies in the JSP?

Samual Sam

Samual Sam

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

2K+ Views

Setting cookies with JSP involves three steps −Step 1: Creating a Cookie objectYou call the Cookie constructor with a cookie name and a cookie value, both of which are strings.Cookie cookie = new Cookie("key", "value");Keep in mind, neither the name nor the value should contain white space or any of ... Read More

Create Septet Tuple in Java using with() method

Samual Sam

Samual Sam

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

64 Views

The with() method is used to create Septet Tuple in Java.Let us first see what we need to work with JavaTuples. To work with Septet class in JavaTuples, you need to import the following package −import org.javatuples.Septet;Note − Steps to download and run JavaTuples program If you are using Eclipse ... Read More

How to remove a MySQL collection named 'group'?

Samual Sam

Samual Sam

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

52 Views

The group is a type of method in MongoDB. It shouldn’t be created as a collection name. Even if you created it, you can easily remove it using getCollection('group').drop();). Let us first create a collection with documents −> db.createCollection('group'); { "ok" : 1 } > db.getCollection('group').insertOne({"StudentName":"Chris"}); {    "acknowledged" : ... Read More

How to use prepared statement for select query in Java with MySQL?

Samual Sam

Samual Sam

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

7K+ Views

You need to use executeQuery() for this. The syntax is as follows −yourPreparedStatementObject=yourConnectionObject.prepareStatement(yourQueryName); yourresultSetObject=yourPreparedStatementObject.executeQuery();Create a table in the database ‘sample’. The query to create a table is as follows −mysql> create table JavaPreparedStatement -> ( -> Id int, -> Name varchar(10), ... Read More

Advertisements