查询在数据库中直接执行时运行完全正常,但它给了我上面的错误..我已经经历了类似的问题,但无法找到任何解决方案..
我的Dao代码
public String BASshiftingStudentsUpdate(HttpServletRequest request)
{
String sql="",msg="";
String[] checkedApps = request.getParameter("checkedApps") != null&& request.getParameter("checkedApps")!=""?request.getParameter("checkedApps").split("\\,") : null;
String ac_year=request.getParameter("acyear");
try
{
if (checkedApps != null)
{
for (int i = 0; i < checkedApps.length; i++)
{
sql=" insert into pmss_school_students_details(admission_no,student_name,parent_name,native_dist,native_mandal,address,caste_code,subcaste_code,admission_year,"
+ "admission_dt,admission_class,present_class,student_photo,entered_by,entered_dt,stu_subcaste_new,mobilenumber,parent_proffession,annual_income,date_of_birth,"
+ "pre_quarterly_marks,pre_annual_marks,achievements,health_problems,height,weight,blood_group,fresh_renewal,identification_marks,orphan,semi_orphan,"
+ "rescued_child,victim,handycapped,school_code,class_promoted,dept_code,dist_office_code,applied_date,stu_id,status,pre_halfyearly_marks,ac_year,"
+ "pre_quarterly_marks_max,pre_halfyearly_marks_max,pre_annual_marks_max,gender,boaders,from_school) "
+ " select admission_no,student_name,parent_name,native_dist,"
+ "native_mandal,address,caste_code,subcaste_code,admission_year,admission_dt,admission_class,present_class+1 as present_class,student_photo,entered_by,entered_dt,"
+ "stu_subcaste_new,mobilenumber,parent_proffession,annual_income,date_of_birth,pre_quarterly_marks,pre_annual_marks,achievements,health_problems,"
+ "height,weight,blood_group,'R' as fresh_renewal,identification_marks,orphan,semi_orphan,rescued_child,victim,handycapped,'"+request.getParameter("to_schools_selected")+"' as school_code,class_promoted,"
+ "dept_code,dist_office_code,applied_date,(substring(stu_id,1,4))::int+1||substr(stu_id,5) as stu_id,'3' as status,pre_halfyearly_marks,(substring(stu_id,1,4))::int+1||'-'||(substring(stu_id,3,2))::int+2 as ac_year,pre_quarterly_marks_max,"
+ "pre_halfyearly_marks_max,pre_annual_marks_max,gender,boaders,school_code from pmss_school_students_details "
+ " where stu_id='"+checkedApps[i]+ "' and school_code='"+ Integer.parseInt(request.getParameter("schoolcode").trim())
+ "' and ac_year=int4(substring('"+ac_year+"',1,4))-1||'-'||int4(substring('"+ac_year+"',6,2))-1";
gen.executeUpdate(sql);
}
}
executeUpdate方法
public int executeUpdate(String sql)
{
Session session = sessionfactory.openSession();
SQLQuery query=null;
int result=0;
try
{
result=session.createSQLQuery(sql).executeUpdate();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (session.isOpen())
{
session.close();
}
}
return result;
}
查询中的列数相同。
答案 0 :(得分:0)
冒号(:
)是Hibernate中命名参数的前缀。确保你逃脱它们,例如\:\:int+1
。