Calling database custom Function Using CallableStatement

By | July 17, 2018

In this post you will learn how to call Stored Function Using JDBC CallableStatement.
Here i am using MYSQL database but you are feel free to choose any database.
Jdbc code would be same for all database only little changes may be in how to create SQL custom function from once database to another

Project structure in eclipse:

DB Script to create SQL function in MYSQL database schema(jdbcdb)

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.

Client program which calls MySQL above created function and returns value

If you run this client program this will ask you to enter two numbers for which you want to find average.

That’s all for topic Calling database custom Function 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 *