Stored Procedures and Calling Them Using JDBC

Krantik Chavan
Updated on 09-Mar-2020 06:32:51

560 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 these procedures.Stored procedures contain IN and OUT parameters, or both. They may return result sets in case you use SELECT statements, they can return multiple result-sets.ExampleSuppose we have a table named Dispatches in the MySQL database with the following data:+--------------+------------------+------------------+------------------+ | Product_Name | Date_Of_Dispatch | Time_Of_Dispatch | Location         | +--------------+------------------+------------------+------------------+ | KeyBoard     | 1970-01-19       | 08:51:36         | Hyderabad ... Read More

What is Result in JDBC: Retrieve Data from ResultSet Object

Daniol Thomas
Updated on 09-Mar-2020 06:31:58

2K+ Views

A ResultSet interface in JDBC represents the tabular data generated by SQL queries. It has a cursor which points to the current row. Initially, this cursor is positioned before the first row.Moving the pointer throughout result setThe next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position. This method returns a boolean value, if there are no rows next to its current position it returns false, else it returns true. Therefore, using this method in the while loop you can iterate the contents of the result set.while(rs.next()){ }Getting the ... Read More

Retrieve All Processes Data of Process API in Java 9

raja
Updated on 09-Mar-2020 05:36:55

814 Views

In Java 9, Process API has been used to control and manage operating system processes. ProcessHandle class provides the process’s native process ID, start time, accumulated CPU time, arguments, command, user, parent process, and descendants. It also provides a method to check processes liveness and to destroy processes. We retrieve all ProcessHandle data as a stream by using the allProcesses() method.In the below example, we retrieve all the processes information.Exampleimport java.util.stream.Stream; import java.util.Optional; import java.util.stream.Stream; public class AllProcessesTest {    public static void main(String args[]) throws InterruptedException {       System.out.println("---------------------------");       System.out.println("All Processes:");       Stream processStream = ProcessHandle.allProcesses();       processStream.forEach(process -> ... Read More

Terminate Process Using Process API in Java 9

raja
Updated on 06-Mar-2020 12:28:44

2K+ Views

In Java 9, Process API supports an easy way to get much information about a process. ProcessHandle interface can identify and provide the control of native processes and method to check processes liveness and destroy the processes whereas ProcessHandle.Info interface can give an Information snapshot of a process. We need to destroy a process by using the destroy() method of the ProcessHandle interface.In the below example, we need to terminate a process by using the ProcessHandle interface.Exampleimport java.io.File; import java.io.IOException; import java.util.Objects; public class DestroyProcessTest {    public static void main(String[] args) throws InterruptedException {       System.out.println("---------------------------");       ... Read More

Importance of ofInstant Method in Java 9

raja
Updated on 06-Mar-2020 10:35:54

221 Views

In Java 9, the ofInstant() method has introduced for conversion. It is a static method of LocalDate, LocalTime, and LocalDateTime classes. This method converts java.time.Instant object to LocalDate that requires a time zone in the form of java.time.ZoneId.Syntaxpublic static LocalTime ofInstant(Instant instant, ZoneId zone) public static LocalDate ofInstant(Instant instant, ZoneId zone) public static LocalDateTime ofInstant(Instant instant, ZoneId zone)Exampleimport java.time.LocalDate; import java.time.LocalTime; import java.time.LocalDateTime; import java.time.Instant; import java.time.ZoneId; public class OfInstantMethodTest {    public static void main(String args[]) { Instant instant = Instant.parse("2020-02-05T02:35:15.245Z"); System.out.println("Instant: " + instant); ... Read More

Select Records from a Table Based on Month Number in MySQL

karthikeya Boyini
Updated on 06-Mar-2020 10:29:45

519 Views

You can select specific month with the help of MONTH() function. The syntax is as follows −SELECT yourColumnName FROM yourTableName WHERE MONTH(yourColumnName) = yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table UserLoginTimeInformation    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserLoginDatetime datetime    -> ); 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 UserLoginTimeInformation(UserLoginDatetime) values(date_add(now(), interval 3 month)); Query OK, 1 row affected (0.14 sec) ... Read More

Negative Value in Unsigned Column in MySQL

Samual Sam
Updated on 06-Mar-2020 10:07:02

711 Views

Error occurs when you set a negative value to UNSIGNED column in MySQL. For example, let us first create a table with an UNSIGNED field −mysql> create table UnsignedDemo    -> (    -> Id int UNSIGNED    -> ); Query OK, 0 rows affected (0.79 sec)The error is as follows whenever you insert negative value to column Id which is declared as UNSIGNED −mysql> INSERT INTO UnsignedDemo VALUES(-100); ERROR 1264 (22003): Out of range value for column 'Id' at row 1ExampleHowever, positive values work well for UNSIGNED. The same is shown in the example below. Insert some records in ... Read More

Show Table Information in MySQL

karthikeya Boyini
Updated on 06-Mar-2020 10:05:22

138 Views

The SHOW TABLE STATUS in MySQL displays the NAME, ENGINE, VERSION, ROWS, CHECKSUM, etc of a table −ExampleLet us first create a table. Here, we are using the MyISAM engine. The query to create a table is as follows −mysql> create table Post_Demo    -> (    -> PostId int,    -> PostName varchar(100),    -> PostDate datetime,    -> PRIMARY KEY(PostId)    -> )ENGINE = MyISAM; Query OK, 0 rows affected (0.28 sec)Now you can check the table status using SHOW TABLE command. The query is as follows −mysql> show table status where Name = 'Post_Demo'\GOutput*************************** 1. row *************************** ... Read More

HAVING Clause with GROUP BY in MySQL

karthikeya Boyini
Updated on 06-Mar-2020 10:03:50

400 Views

To use HAVING with GROUPBY in MySQL, the following is the syntax. Here, we have set a condition under HAVING to get check for maximum value condition −SELECT yourColumnName FROM yourTableName GROUP BY yourColumnName HAVING MAX(yourColumnName) < yourValue;Let us see an example by creating a table in MySQL −mysql> create table WhereAfterGroupDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserProcess int, -> UserThreadId int -> ); Query OK, 0 rows affected (5.74 sec)ExampleInsert some records in the table using insert command. The query is as follows −mysql> insert into WhereAfterGroupDemo(UserProcess, UserThreadId) values(1211, 3); Query OK, 1 ... Read More

Forward List Clear and Erase After in C++ STL

Sunidhi Bansal
Updated on 06-Mar-2020 07:37:29

443 Views

In this article we will be discussing the working, syntax and examples of forward_list::clear() and forward_list::erase_after() functions in C++.What is a Forward_list in STL?Forward list are sequence containers that allow constant time insert and erase operations anywhere within the sequence. Forward lists are implemented as singly linked lists. The ordering is kept by the association to each element of a link to the next element in the sequence.What is forward_list::clear()?forward_list::clear() is an inbuilt function in C++ STL which is declared in header file. clear() is used when we have to remove all the elements of the forward list at ... Read More

Advertisements