Convert Java Util Date to Java Time LocalDateTime

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

192 Views

First, set the date −java.util.Date date = new Date();Now, convert the above Date to java.time.LocalDateTime −java.time.LocalDateTime dateTime =    java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());Exampleimport java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       java.util.Date date = new Date();       System.out.println("Date = "+date);       java.time.LocalDateTime dateTime =          java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());       System.out.println("LocalDateTime = "+dateTime);    } }OutputDate = Thu Apr 18 23:39:34 IST 2019 LocalDateTime = 2019-04-18T23:39:34.400

Convert ISODate to Numerical Value in MongoDB

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

471 Views

You can use getTime() for this. Following is the syntax −yourVariableName.getTime();Convert ISODate to numerical value −> var arrivalDate=ISODate('2019-04-18 13:50:45');Following is the query to convert ISODate to numerical value −> arrivalDate.getTime();This will produce the following output −1555595445000 Let us verify that it is a correct numerical value for ISODate or not. Following is the query to get correct ISODate whenever we apply above numeric value −> new Date(1555595445000);This will produce the following output −ISODate("2019-04-18T13:50:45Z")Yes, this is a correct ISODate.

Correctly Enclose Subquery in MySQL

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

282 Views

You need to close the subquery in a parenthesis. The syntax is as follows −select if((select count(*) from yourTableName ), 'Yes', 'No') as anyAliasName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SelectIfDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(10) -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into SelectIfDemo(Name) values('John'); Query OK, ... Read More

Java 8 Clock getZone Method

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

189 Views

The time zone required for the date and time creation can be obtained using the method getZone() in the Clock Class in Java. This method requires no parameters and it returns the required time zone.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Clock c = Clock.systemDefaultZone();     ZoneId z = c.getZone(); System.out.println("The clock is: " + c); System.out.println("The ZoneId is: " + z); } ... Read More

AddAtX Method for Pair Class in Java Tuples

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

98 Views

The addAtX() method is used to add value at a particular position represented by X here.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Here we have also used the Triplet class, therefore import the following package −import org.javatuples.Triplet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an ... Read More

Change MySQL Column Datatype from TEXT to TIMESTAMP

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

3K+ Views

To change a MySQL column datatype from text to timestamp, you need to use ALTER command.The syntax is as followsALTER TABLE yourTableName MODIFY COLUMN yourColumnName TIMESTAMP;To understand the above syntax, let us create a table.The query to create a table is as followsmysql> create table textTotimestampdemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > Source text    - > ); Query OK, 0 rows affected (0.44 sec)Here is the description of table using DESC command.The syntax is as followsDESC yourTableName;The query is as followsmysql> desc textTotimestampdemo;The following is the output+--------+---------+------+-----+---------+----------------+ | ... Read More

Uploaded Files Storage Location in JSP

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

516 Views

A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file can be a text file or a binary or an image file or just any document.Creating a File Upload FormLet us now understand how to create a file upload form. The following HTML code creates an uploader form. Following are the important points to be noted down −The form method attribute should be set to POST method and the GET method cannot be used.The form enctype attribute should be set to multipart/form-data.The form action attribute should be set ... Read More

LongStream forEach Method in Java

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

192 Views

The forEach() method of the LongStream class in Java performs an action for each element of this stream.The syntax is as followsvoid forEach(LongConsumer action)Here, the parameter action is a non-interfering action to perform on the elements. LongConsumer represents an operation that accepts a single long-valued argument and returns no result.To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;The following is an example to implement LongStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(1000L, 12000L, ... Read More

List All Users in the Mongo Shell

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

13K+ Views

In order to list all users in the Mongo shell, use the getUsers() method or show command.Case 1 − Using getUsers()The syntax is as follows −db.getUsers();Case 2 − Using show commandThe syntax is as follows −show users;Let us implement both the syntaxes in order to list all users in the Mongo shell.Case 1 − The first query is as follows −> db.getUsers();The following is the output −[    {       "_id" : "test.John",       "user" : "John",       "db" : "test",       "roles" : [          {     ... Read More

RowSet Scrollable: Explanation with Example

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

504 Views

A RowSet object is similar to ResultSet, it also stores tabular data, in addition to the features of a ResultSet. A RowSet follows the JavaBeans component model.If you Retrieve a ResultSet object by default the cursor of it moves only in forward direction. i.e. you can retrieve the contents of it from first to last.But, in a scrollable result set, the cursor can scroll forward and backward and you can retrieve data backward too.To make ResultSet object scrollable, you need to create one as shown below −Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);Whereas, a RowSet object is Scrollable by default. Therefore, whenever ... Read More

Advertisements