Get ResultSet By Calling StoredProcedure Using CallableStatement

By | July 17, 2018

In this post we will learn how map number of rows return by calling stored procedure in JDBC Result set.

Project structure in eclipse:

SQL Query to create employee_table in MySQL (jdbcdb schema)
(Note:Make sure you created employee_table and Stored procedure(getEmployeeById) in jdbcdb database schema)

Insert some records in employee_table as below

DBUtil.java class which is responsible to connect with MySQL database.
this util class uses getConnection() method of java.sql.DriverManager class
public static Connection getConnection(String url,String user, String password) throws SQLException
This method takes three parameters database URL,username and password.
Here database username =”root”,password  = “root”  what password had supplied during MYSQL database installation time and finally database URL =“jdbc:mysql://localhost:3306/jdbcdb” Where jdbc is the API, mysql is the database, localhost is the server name on which mysql  database server is running, we may also use IP address instead machine name, 3306 is the port number and jdbcdb(Make you you have created this schema in MySQL database) is the database name. You may use any database name, in that case, You need to replace the jdbcdb with your database name.

Now let’s run our ClientTest.java class to read an employee record from stored proc and map into jdbc ResultSet.

if you run this program it will ask you to provide employee Id.

Here i have provided employee as Id 2  so stored procedure fetching employee whose id is 2 and same is mapping with JDBC ResultSet

That’s all for topic Get ResultSet By Calling StoredProcedure Using CallableStatement
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *