Spring JdbcTemplate – Call Function

Function

DROP FUNCTION IF EXISTS fn_is_menu_present;

DELIMITER $$

CREATE FUNCTION fn_is_menu_present(in_name VARCHAR(20))
RETURNS BOOLEAN
    
    BEGIN
	RETURN EXISTS(SELECT 1 FROM menu WHERE NAME=in_name);
    END$$

DELIMITER ;

SELECT fn_is_menu_present('idli');

DAO

public Boolean validateMenu(String name) {
String sql = "select fn_is_menu_present(?)";
Boolean isAvailable= jdbcTemplate.queryForObject(sql, new Object[] { name },    Boolean.class);
return isAvailable;
}

TestDAO

MenuDAO dao = new MenuDAO();
Boolean isValid = dao.validateMenu("idli");
System.out.println(isValid);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s