public Employee getEmployee(int id) throws SQLException{
Employee employee=null;
String sql="SELECT * FORM EMPLOYEE WHERE EMPLOYEE_NUMBER=?";
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=dataSource.getConnection();
ps=conn.prepareStatement(sql);
ps.setInt(1,id);
rs=ps.executeQuery();
while(rs.next())
{
employee=new Employee();
employee.setId(rs.getInt("ID"));
employee.setEmployeeNumber(rs.getInt("EMPLOYEE_NUMBER"));
employee.setFirstName(rs.getString("FIRST_NAME");
employee.setLastName(rs.getString("LAST_NAME"));
employee.setTitle(rs.getString("TITLE"));
}
} finally{
try{
if(rs!=null) rs.close();
} finally{
try{
if(ps!=null) ps.close();
} finally{
if(conn!=null) conn.close();
}
}
}
return employee;
}
example of well-written jdbc code
最新推荐文章于 2024-09-14 18:42:05 发布