Found 4331 Articles for Java 8

DoubleStream count() method in Java

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

115 Views

The count() method of the DoubleStream class returns the count of the elements in the stream.The syntax is as follows:long count()To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create DoubleStream and add some elements:DoubleStream doubleStream = DoubleStream.of(50.8, 67.9, 35.7, 23.6, 89.9);Now, get the count of elements in the DoubleStream:long res = doubleStream.count();The following is an example to implement DoubleStream count() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(50.8, 67.9, 35.7, 23.6, 89.9);       long res = doubleStream.count();       ... Read More

DoubleStream min() method in Java

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

77 Views

The min() method of the DoubleStream class returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if this stream is empty.The syntax is as follows:OptionalDoublemin()Here, OptionalDouble is a container object which may or may not contain a double valueTo use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create a DoubleStream and add elements to the stream:DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);Get the maximum element from the DoubleStream:OptionalDouble res = doubleStream.max();The following is an example to implement DoubleStream min() method in Java:Example Live Demoimport java.util.OptionalDouble; import java.util.stream.DoubleStream; public class Demo {    public ... Read More

LongStream min() method in Java

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

67 Views

The min() method of the LongStream class in Java returns an OptionalLong describing the minimum element of this stream, or an empty optional if this stream is empty.The syntax is as follows:OptionalLong min()Here, OptionalLong is a container object which may or may not contain a long value.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following is an example to implement LongStream min() method in Java. The isPresent() method of the OptionalLong class returns true if the value is present:Example Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {     ... Read More

IntStream sequential() method in Java

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

304 Views

The sequential() method of the IntStream class in Java is used to return a sequential IntStream. The syntax is as follows:IntStream sequential()First, create an IntStream and elements in a range using the range() method:IntStream intStream1 = IntStream.range(11, 21);Now, for a sequential IntStream, use the sequential() method like this:IntStream intStream2 = intStream1.sequential();The following is an example to implement IntStream sequential() method in Java:Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream1 = IntStream.range(11, 21);       IntStream intStream2 = intStream1.sequential();       intStream2.forEach(System.out::println);    } }Output11 12 ... Read More

How to retrieve multiple ResultSets from a stored procedure using a JDBC program?

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

6K+ Views

Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.Retrieving Results from a procedure:You can call an existing stored procedure using the CallableStatement. The prepareCall() method of the Connection interface accepts the procedure call in string format and returns a callable statement object.CallableStatement cstmt = con.prepareCall("{call sampleProcedure()}");Execute the above created callable statement using ... Read More

How to connect to a MongoDB database using a JDBC program?

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

1K+ Views

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.Before you start connecting MongoDB in you need to make sure that you have MongoDB JDBC driver. If not, download the jar from the path Download mongo.jar and, add it to your classpath.ExampleFollowing JDBC program establishes connection with the MongoDB database and creates a collection in it.import com.mongodb.client.MongoDatabase; import com.mongodb.MongoClient; import com.mongodb.MongoCredential; public class CreatingCollection {    public static void main( String args[] ) {       // Creating a Mongo client       MongoClient ... Read More

How to connect to PostgreSQL database using a JDBC program?

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

761 Views

PostgreSQL is an open source relational database management system (DBMS) developed by a worldwide team of volunteers. PostgreSQL is not controlled by any corporation or other private entity and the source code is available free of charge.PostgreSQL runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It supports text, images, sounds, and video, and includes programming interfaces for C / C++, Java, Perl, Python, Ruby, Tcl and Open Database Connectivity (ODBC).Download the latest version of postgresql- from postgresql-jdbc repository.Add downloaded jar file postgresql-(VERSION).jdbc.jar in your class path.ExampleFollowing JDBC program ... Read More

How to connect to HSQLDB database using a JDBC program?

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

653 Views

HSQLDB is a relational database management system implemented in pure Java. You can easily embed this database to your application using JDBC. Or you can use the operations separately.Installing HSQLDB:Download the latest version of HSQLDB database.Install HSQLDB following the steps given in HSQLDB Tutorial.Make sure that the HSQLDB database is up and running. The URL to connect to this database is jdbc:hsqldb:hsql://host_name/database_name and the driver class name is org.hsqldb.jdbc.JDBCDriver. Download the driver and set classpath to it.ExampleFollowing JDBC program establishes a connection with HSQL database.import java.sql.Connection; import java.sql.DriverManager; public class ConnectDatabase {    public static void main(String[] args) {   ... Read More

How to get the current value of a particular row from a database using JDBC?

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

1K+ Views

The refreshRow() method of the ResultSet interface refreshes the current row with the most recent value in the database.rs.refreshRow()Assume we have a table named cricketers_data with 7 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  | Lumara     | Sangakkara | ... Read More

How to move the pointer of a ResultSet to the end of the table using JDBC?

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

83 Views

The afterLast() method of the ResultSet interface moves the cursor/pointer after the last row of the ResultSet object.rs.afterLast();Assume we have a table name dataset as shown below:+--------------+-----------+ | mobile_brand | unit_sale | +--------------+-----------+ | Iphone       | 3000      | | Samsung      | 4000      | | Nokia        | 5000      | | Vivo         | 1500      | | Oppo         | 900       | | MI           | 6400      | | MotoG   ... Read More

Advertisements