Instant Truncatedto Method in Java

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

963 Views

An immutable truncated Instant can be obtained using the truncatedTo() method in the Instant class in Java. This method requires a single parameter i.e. the TemporalUnit till which the Instant is truncated and it returns the immutable truncated Instant.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant instant = Instant.now(); System.out.println("The current instant is: " + instant); Instant truncatedInstant = instant.truncatedTo(ChronoUnit.MINUTES); ... Read More

LongStream empty Method in Java

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

130 Views

The empty() method of the LongStream class in Java returns an empty sequential LongStream.The syntax is as follows.static LongStream empty()To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream empty() method in Java.Example Live Demoimport java.util.stream.LongStream; public class GFG {    public static void main(String[] args) {       LongStream longStream = LongStream.empty();       System.out.println("The count of elements in the stream: "+longStream.count());    } }OutputThe count of elements in the stream: 0

LongStream map Method in Java

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

139 Views

The map() method of the LongStream class in Java returns a stream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows:LongStream map(LongUnaryOperator mapper)Here, the parameter mapper is a stateless function to apply to each element. The LongUnaryOperator represents an operation on a single long-valued operand that produces a long-valued result.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;Create a LongStream and add some elements:LongStream longStream1 = LongStream.of(15L, 30L, 45L, 67L, 80L);Now, create another LongStream and map it to a condition set for the elements of longStream1:LongStream longStream2 ... Read More

MySQL SELECT ORDER BY Acts Like a String Not a Number

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

221 Views

You can use the following syntax if your column has varchar data type −select yourColumnName FROM yourTableName ORDER BY yourColumnName +0 DESC;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table selectOrderdemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100),    -> RankNumber varchar(100)    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into selectOrderdemo(Name, RankNumber) values('Larry', -100); Query OK, 1 row affected (0.23 ... Read More

Drop Constraint on a Column of a Table in a Database Using JDBC API

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

356 Views

You can drop a constraint on a column of a table using the ALTER TABLE command.SyntaxALTER TABLE table_name DROP CONSTRAINT MyUniqueConstraint;Assume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  | UNI | NULL    | | | CustomerName | varchar(255) | YES  |     | NULL    | ... Read More

Query MongoDB with Length Criteria

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

192 Views

To query MongoDB with length criteria, you can use regex. Following is the syntaxdb.yourCollectionName.find({ ‘yourFieldName’: { $regex: /^.{yourLengthValue1, yourLengthValue2}$/ } });Let us create a collection with documents. Following is the query> db.queryLengthDemo.insertOne({"StudentFullName":"John Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01ae353decbc2fc927c0") } > db.queryLengthDemo.insertOne({"StudentFullName":"John Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01b4353decbc2fc927c1") } > db.queryLengthDemo.insertOne({"StudentFullName":"David Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01c2353decbc2fc927c2") } > db.queryLengthDemo.insertOne({"StudentFullName":"Robert Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01e2353decbc2fc927c3") } > db.queryLengthDemo.insertOne({"StudentFullName":"Chris Williams"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a01f1353decbc2fc927c4") }Following is the query to display ... Read More

MySQL Query to Retrieve Records from Comma-Separated List

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

538 Views

To retrieve records from the part of a comma-separated list, you can use built in function FIND_IN_SET().Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Marks varchar(200)    ); Query OK, 0 rows affected (0.61 sec)Following is the query to insert some records in the table using insert command −mysql> insert into DemoTable(Name, Marks) values('Larry', '98, 34, 56, 89'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Marks) values('Chris', '67, 87, 92, 99'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More

Count Distinct Value in MongoDB

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

408 Views

Use the concept of length to count distinct value. Following is the syntax −db.yourCollectionName.distinct("yourFieldName").length;Let us create a collection with documents −> db.countDistinctDemo.insertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6166de8cc557214c0dfa") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd616ade8cc557214c0dfb") } > db.countDistinctDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd616cde8cc557214c0dfc") } > db.countDistinctDemo.insertOne({"StudentName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6170de8cc557214c0dfd") } > db.countDistinctDemo.insertOne({"StudentName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6175de8cc557214c0dfe") } > db.countDistinctDemo.insertOne({"StudentName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6181de8cc557214c0dff") }Display all documents from a collection with the help ... Read More

MySQL Merge Selects Together

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

212 Views

To merge selects together, you need to use GROUP BY clause. To understand the concept, let us create a table. The query to create a table is as follows −mysql> create table MergingSelectDemo    -> (    -> RoomServicesId int,    -> RoomId int,    -> ServiceId int    -> ); Query OK, 0 rows affected (1.98 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into MergingSelectDemo values(10, 10, 10); Query OK, 1 row affected (0.29 sec) mysql> insert into MergingSelectDemo values(20, 10, 20); Query OK, 1 row affected ... Read More

ByteBuffer as LongBuffer Method in Java

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

116 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          LongBuffer bufferL = bufferB.asLongBuffer();       ... Read More

Advertisements