Found 4336 Articles for Java 8

How to find the current row of a ResultSet object using JDBC?

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

546 Views

The getRow() method of the ResultSet class returns the row number at which the ResultSet pointer exists in the current instance.Assume we have a table named cricketers_data with 6 records as shown below:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country     | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | Lumara     | Sangakkara | 1977-10-27    | Matale     ... Read More

How to fetch the value from a KeyValue Tuple in Java?

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

151 Views

To fetch the value from a KeyValue tuple in Java, use the getValue() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to fetch the ... Read More

Create KeyValue Tuple from a List collection in Java

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

79 Views

To create KeyValue tuple from List collection, use the fromCollection() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create KeyValue Tuple from List ... Read More

How to move the result set pointer to required position?

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

182 Views

The absolute() method of the ResultSet interface accepts an integer value representing the index of a row and moves the ResultSet pointer of the current ResultSet object to the specified position.Assume we have a table named cricketers_data with 6 records as shown below:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country     | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | Lumara   ... Read More

DoubleStream average() method in Java

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

1K+ Views

The average() method of the DoubleStream class in Java returns an OptionalDouble which is the arithmetic mean of elements of this stream. If the stream is empty, empty is returned.The syntax is as follows:OptionalDouble average()Here, OptionalDouble is a container object which may or may not contain a double value.To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;First, create DoubleStream and add some elements:DoubleStream doubleStream = DoubleStream.of(50.8, 35.7, 49.5, 12.7, 89.7, 97.4);Get the average of the elements of the stream:OptionalDouble res = doubleStream.average();The following is an example to implement DoubleStream average() method in Java:Example Live Demoimport java.util.*; import java.util.stream.DoubleStream; ... Read More

Create Octet Tuple from an array in Java

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

95 Views

To create Octet Tuple from an array in Java, use the fromArray() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:import org.javatuples.Octet;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create Octet Tuple ... Read More

How to delete a row from ResultSet object using JDBC?

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

860 Views

The deleteRow() method of the ResultSet interface deletes the current row from the current ResultSet object.//Deleting a column from the ResultSet object rs.deleteRow();Assume we have a table named Cricketers_Data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1  | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India | | 2  | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | 3 ... Read More

ArrayBlockingQueue put() method in Java

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

81 Views

The put() method of the ArrayBlockingQueue class inserts the specified element at the tail of this queue. It waits for the space to become available, if the queue is full.The syntax is as follows:void put(E e)Here, e is the element to be inserted.To work with ArrayBlockingQueue class, you need to import the following package:import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement put() method of Java ArrayBlockingQueue class:Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(7);       q.put(200);       q.put(310);     ... Read More

DoubleStream forEach() method in Java

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

101 Views

The forEach() method of the DoubleStream class performs an action for each element of this stream.The syntax is as follows:void forEach(DoubleConsumer action)Here, DoubleConsumer represents an operation that accepts a single double-valued argument and returns no result. The parameter action is a non-interfering action to perform on the elements.To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the stream:DoubleStream doubleStream = DoubleStream.of(45.7, 67.8, 89.7, 95.6);Now, display the elements:doubleStream.forEach(System.out::println);The following is an example to implement DoubleStream forEach() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args){ ... Read More

How to create a table in JDBC using another table?

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

349 Views

You can create a table same as an existing table using the following syntax:CREATE TABLE new_table as SELECT * from old_table;Assume we have a table named dispatches with 5 records as shown below:+-------------+--------------+--------------+--------------+-------+----------------+ | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location       | +-------------+--------------+--------------+--------------+-------+----------------+ | Key-Board   | Raja         | 2019-09-01   | 05:30:00     | 7000  | Hyderabad     | | Earphones   | Roja         | 2019-05-01   | 05:30:00     | 2000  | Vishakhapatnam | | Mouse       ... Read More

Advertisements