java - How to return mysql function select count -


i tring count value of sql select using mysql function. functions executes without errors when try value using java following error 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 mysql funtion

delimiter // create function application_api_get_new_application_count() returns integer begin if((select count(*) temp application_view status = 'new')>0)     return temp; end if;  return 0;  end// 

this 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 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 view table

create or replace view application_view     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     application_tab; 

this issue has nothing java, mysql function incorrect.

first of all, function overcomplicated if. if returned count zero, still return count instead of specific number.

secondly, not have temp variable in function, there nothing return.

i declare integer variable, fetch count , return variable's value:

... declare temp int; select count(*) temp application_view status = 'new'; return temp; ... 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -