filmov
tv
Java JDBC Tutorial – Part 6.4: Calling MySQL Stored Procedures with Java
Показать описание
---
---
In this video tutorial we will learn how to call MySQL Stored Procedures with Java. This video covers stored procedures that return result sets.
---
Transcript
Time - 00:00
Time - 00:11
In this video, we're going to focus on stored procedures that return result sets. Check out my other videos that covered different types of parameters, such as IN, and INOUT.
Time - 00:22
For this tutorial we will use the following table, employees. The table has a sample data for testing. I havea a SQL zip file that you can download, it'll create the table, add sample data and also set up the stored procedures. You can download it from the link below.
Time - 00:39
We'll call a stored procedure that returns a result set for us to process. Our DBA created a stored procedure called "Get Employees for Department." The first parameters the department main, and the stored procedure will return the results as a result set.
Time - 00:55
To call the stored procedure, we prepared columns before. Using a question mark as a parameter place holder. We set the first input parameter as the name of the department. Then we execute the stored procedure. Once the execution is complete, then we can retrieve the result set by calling, get result set.
Time - 01:15
Okay, so let's switch Eclipse and see this in action. I have a sample Java program called, Get Employees for Department. Let's walk through the code. The first thing we'll do is get a connection to the database. We'll also set up our variables for the department name. Then I'll prepare a call to the stored procedure. I'll make use of the question mark as a parameter place holder. Then I'll set the parameter value. I will actually call the stored procedure. Then I will actually retrieve the result set from the stored procedure. Now, I'll call a helper method that will actually display the result set.
Time - 01:53
Now, let's go ahead and run the application. As we can see we make a call to the stored procedure, we pass in the department for engineering, we get the results, we call our helper method and it displays the results. Which looks pretty good. Let's go ahead and verify this in our SQL tool.
Time - 02:17
I'll move over to the tool, I have this query, select * from employees where department equals engineering. I will execute and I get four results. This matches with the information that we have from the Java program. This looks very good, so we're successful.
Time - 02:35
Комментарии