最近做个项目,我从一个表里查empid,用这个empid到另一个表里查别的东西,发现一个问题只要用到preparedstatement 的setint就抛出异常如题
具体涉及到的代码如下:
public final static String PROMOTION = "select * from hr_admin_promotion_list";
public final static String PROMOTION_1="select * from hr_admin_employeeinf where empid=?";
public static ArrayList promotionList(DataSource ds){
ArrayList promotionList = null;
Promotion promotion = null;
Connection con = null;
Statement stm = null;
PreparedStatement ps = null;
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
System.out.println("___________________function promotionlist________________________________________");
promotionList = new ArrayList();
promotion = new Promotion();
try{
con = ds.getConnection();
stm = con.createStatement();
rs = stm.executeQuery(PROMOTION);
while(rs.next())
{
System.out.println("---------------looking at promotionlist-----------------------------------------");
//select empid from table promotion_list
int empId = rs.getInt("employeeid");
int promotedDesignationId = rs.getInt("promoted_designation");
int promotedDepartmentId = rs.getInt("promoted_department");
String empName =null;
String department = null;
int designationid =0;
String currentDesignation = null;
String promotedDesignation = null;
String PromotedDepartment = null;
//select empname department designationid from table employeeinf
System.out.println("_________________________________________"+empId);
ps = con.prepareStatement(PROMOTION_1);
ps.setInt(1,empId);
rs1 = ps.executeQuery();
if(rs1.next())
{
System.out.println("---------------------in----promotion_1----------------------------------------------");
empName = rs1.getString("employeeinfo_name");
department = rs1.getString("department");
designationid = rs1.getInt("designationid");
rs1.close(); ps.close();
}
//select current designation and promoted designation from table designation
ps1 = con.prepareStatement(PROMOTION_2);
ps1.setInt(1,designationid);
rs2 = ps1.executeQuery();
if(rs2.next())
{
System.out.println("---------------------in----promotion_2----------------------------------------------");
currentDesignation = rs2.getString("Designation_Name");
ps1.setInt(1,promotedDesignationId);
rs2 = ps1.executeQuery();
promotedDesignation = rs2.getString("Designation_Name");
ps1.close();rs2.close();
}
//select current promoted department from table hr_xmart_department
ps2 = con.prepareStatement(PROMOTION_3);
ps2.setInt(1,promotedDepartmentId);
rs3 = ps2.executeQuery();
if(rs3.next())
{
PromotedDepartment = rs3.getString("department_name");
ps2.close(); rs3.close();
}
promotion.setEmpId(empId);
promotion.setEmpName(empName);
promotion.setCurrentDept(department);
promotion.setCurrentDesignation(currentDesignation);
promotion.setPromotedDept(PromotedDepartment);
promotion.setPromotedDesignation(promotedDesignation); promotionList.add(promotion);
}
}catch(Exception e)
{
System.out.println("_____________________________________________"+e);
}
return promotionList;
}
运行结果如下:
--------------looking at promotionlist-----------------------------------------
_________________________________________7000910
_____________________________________________java.sql.SQLException: ORA-00904: "EMPID": invalid identifier
具体涉及到的代码如下:
public final static String PROMOTION = "select * from hr_admin_promotion_list";
public final static String PROMOTION_1="select * from hr_admin_employeeinf where empid=?";
public static ArrayList promotionList(DataSource ds){
ArrayList promotionList = null;
Promotion promotion = null;
Connection con = null;
Statement stm = null;
PreparedStatement ps = null;
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
System.out.println("___________________function promotionlist________________________________________");
promotionList = new ArrayList();
promotion = new Promotion();
try{
con = ds.getConnection();
stm = con.createStatement();
rs = stm.executeQuery(PROMOTION);
while(rs.next())
{
System.out.println("---------------looking at promotionlist-----------------------------------------");
//select empid from table promotion_list
int empId = rs.getInt("employeeid");
int promotedDesignationId = rs.getInt("promoted_designation");
int promotedDepartmentId = rs.getInt("promoted_department");
String empName =null;
String department = null;
int designationid =0;
String currentDesignation = null;
String promotedDesignation = null;
String PromotedDepartment = null;
//select empname department designationid from table employeeinf
System.out.println("_________________________________________"+empId);
ps = con.prepareStatement(PROMOTION_1);
ps.setInt(1,empId);
rs1 = ps.executeQuery();
if(rs1.next())
{
System.out.println("---------------------in----promotion_1----------------------------------------------");
empName = rs1.getString("employeeinfo_name");
department = rs1.getString("department");
designationid = rs1.getInt("designationid");
rs1.close(); ps.close();
}
//select current designation and promoted designation from table designation
ps1 = con.prepareStatement(PROMOTION_2);
ps1.setInt(1,designationid);
rs2 = ps1.executeQuery();
if(rs2.next())
{
System.out.println("---------------------in----promotion_2----------------------------------------------");
currentDesignation = rs2.getString("Designation_Name");
ps1.setInt(1,promotedDesignationId);
rs2 = ps1.executeQuery();
promotedDesignation = rs2.getString("Designation_Name");
ps1.close();rs2.close();
}
//select current promoted department from table hr_xmart_department
ps2 = con.prepareStatement(PROMOTION_3);
ps2.setInt(1,promotedDepartmentId);
rs3 = ps2.executeQuery();
if(rs3.next())
{
PromotedDepartment = rs3.getString("department_name");
ps2.close(); rs3.close();
}
promotion.setEmpId(empId);
promotion.setEmpName(empName);
promotion.setCurrentDept(department);
promotion.setCurrentDesignation(currentDesignation);
promotion.setPromotedDept(PromotedDepartment);
promotion.setPromotedDesignation(promotedDesignation); promotionList.add(promotion);
}
}catch(Exception e)
{
System.out.println("_____________________________________________"+e);
}
return promotionList;
}
运行结果如下:
--------------looking at promotionlist-----------------------------------------
_________________________________________7000910
_____________________________________________java.sql.SQLException: ORA-00904: "EMPID": invalid identifier
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货