I am tring to get the count value of a sql select using a mysql function. Functions executes without errors but When I try to get the value using java following error is appeared.
25-May-2016 05:14:02.180 SEVERE [http-nio-8084-exec-109] CORE.ApplicationMgt.Get_New_Application_Count null com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'temp' in 'field list'
Here is mysql funtion
DELIMITER //
CREATE FUNCTION APPLICATION_API_Get_New_Application_Count() RETURNS INTEGER
BEGIN
IF((SELECT COUNT(*) AS temp FROM application_view WHERE status = 'NEW')>0) THEN
RETURN temp;
END IF;
RETURN 0;
END//
This is the function call point
public int Get_New_Application_Count() {
CallableStatement stmt;
int temp_ = 0;
try {
stmt = MySqlManager.getDbConnection().prepareCall("{ ? = call APPLICATION_API_Get_New_Application_Count()}");
stmt.registerOutParameter(1, java.sql.Types.INTEGER);
stmt.execute();
temp_ = stmt.getInt(1);
} catch (SQLException ex) {
Logger.getLogger(PermissionSetMgt.class.getName()).log(Level.SEVERE, null, ex);
}
return temp_;
}
This is the table
CREATE TABLE IF NOT EXISTS application_tab (
nic VARCHAR(10) NOT NULL,
apply_degree VARCHAR(45) NOT NULL,
user_email VARCHAR(60) NOT NULL,
title VARCHAR(10) NOT NULL,
initials VARCHAR(15) NULL,
name_from_initials VARCHAR(100) NULL,
first_name VARCHAR(45) NULL,
middle_name VARCHAR(45) NULL,
last_name VARCHAR(45) NULL,
birth_day DATE NOT NULL,
gender VARCHAR(1) NOT NULL,
civil_status VARCHAR(15) NOT NULL,
course_type VARCHAR(25) NOT NULL,
com_lit_opt1 VARCHAR(2) NOT NULL,
com_lit_opt2 VARCHAR(2) NOT NULL,
com_lit_opt3 VARCHAR(2) NOT NULL,
com_lit_opt4 VARCHAR(2) NOT NULL,
designation VARCHAR(50) NULL,
org_name VARCHAR(50) NULL,
appointed_date DATE NULL,
status VARCHAR(15) NOT NULL,
PRIMARY KEY (nic, apply_degree));
This is the view from this table
CREATE OR REPLACE VIEW application_view AS
SELECT nic nic,
apply_degree apply_degree,
user_email user_email,
title title,
initials initials,
name_from_initials name_from_initials,
first_name first_name,
middle_name middle_name,
last_name last_name,
birth_day birth_day,
gender gender,
civil_status civil_status,
course_type course_type,
com_lit_opt1 com_lit_opt1,
com_lit_opt2 com_lit_opt2,
com_lit_opt3 com_lit_opt3,
com_lit_opt4 com_lit_opt4,
designation job,
org_name organization_name,
appointed_date appointed_date,
status status
FROM application_tab;