package com.goldsoft.dao.example;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.goldsoft.bean.example.Student;
import com.goldsoft.util.DBManager;
public class StudentDAO {
// public int add(Student student){
// PreparedStatement pstmt=null;//ctrl+shift+o
// try{
// pstmt=DBManager.getConnection().prepareStatement(
// "insert into example_student_tab(gradeid,studentid,name,birthday,sex,height,description)"+
// "values(example_student_seq.nextavl,?,?,?,?,?,?)");
// pstmt.setInt(1,student.getGradeid());
// pstmt.setInt(2,student.getStudentid());
// pstmt.setString(3,student.getName());
// pstmt.setString(4,student.getBirthday());
// pstmt.setInt(5,student.getSex());
// //pstmt.setString(6,String.parseString(student.getHeight()));
// pstmt.setString(7,student.getDescription());
// }catch(Exception e){
// e.printStackTrace();
// }finally{
// DBManager.clearup(pstmt);
// }
//
// return 0;
// }
private static final String SQL_STUDENT_ADD=
"insert into example_student_tab(gradeid,studentid,name,birthday,sex,height,description)"
+"values(?,example_student_seq.nextval,?,to_date(?,'yyyy-MM-dd'),?,?,?)";
public int add(Student student){
PreparedStatement pstmt=null;
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_STUDENT_ADD);
pstmt.setInt(1,student.getGradeid());
pstmt.setString(2,student.getName());
pstmt.setString(3,student.getBirthday());
pstmt.setInt(4,student.getSex());
pstmt.setFloat(5,student.getHeight());
pstmt.setString(6,student.getDescription());
int x=pstmt.executeUpdate();
return x;
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt);
}
return 0;
}
private static final String SQL_STUDENT_UPDATE=
"update example_student_tab set gradeid=?,name=?,birthday=to_date(?,'yyyy-mm-dd'),sex=?,height=?,description=? where studentid=?";
public int update(Student student){
PreparedStatement pstmt=null;
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_STUDENT_UPDATE);
pstmt.setInt(1,student.getGradeid());
pstmt.setString(2,student.getName());
pstmt.setString(3,student.getBirthday());
pstmt.setInt(4,student.getSex());
pstmt.setFloat(5,student.getHeight());
pstmt.setString(6,student.getDescription());
pstmt.setInt(7,student.getStudentid());
int x=pstmt.executeUpdate();
return x;
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt);
}
return 0;
}
private static final String SQL_STUDENT_DELETE=
"delete from example_student_tab where studentid=?";
public int delete(int studentid){
PreparedStatement pstmt=null;
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_STUDENT_DELETE);
pstmt.setInt(1,studentid);
int x=pstmt.executeUpdate();
return 0;
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt);
}
return 0;
}
private static final String SQL_GET_STUDENT=
"select s.*,to_char(s.birthday,'yyyy-mm-dd') birthday1 from example_student_tab s where studentid=?";
public Student get(int studentid){
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_GET_STUDENT);
pstmt.setInt(1,studentid);
rs=pstmt.executeQuery();
if(rs.next()){
Student st=new Student();
st.setGradeid(rs.getInt("gradeid"));
st.setStudentid(rs.getInt("studentid"));
st.setName(rs.getString("name"));
st.setBirthday(rs.getString("birthday1"));
st.setSex(rs.getInt("sex"));
st.setHeight(rs.getFloat("height"));
st.setDescription(rs.getString("description"));
return st;
}
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt);
}
return null;
}
private static final String SQL_GET_STUDENT_LIST="select g.name gname, s.*,to_char(birthday,'yyyy-MM-dd') birthday1 from example_grade_tab g,example_student_tab s where g.gradeid=s.gradeid";
public List<Map<String,String>> getList(){
PreparedStatement pstmt=null;
ResultSet rs=null;
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_GET_STUDENT_LIST);
rs=pstmt.executeQuery();
Map<String,String> map=null;
while(rs.next()){
map=new HashMap<String,String>();
map.put("gname",rs.getString("gname"));
map.put("studentid", String.valueOf(rs.getInt("studentid")));
map.put("name",rs.getString("name"));
map.put("birthday",rs.getString("birthday1"));
map.put("sex",rs.getInt("sex")==0?"男":"女");
map.put("height",String.valueOf(rs.getFloat("height")));
map.put("description",rs.getString("description"));
list.add(map);
}
}
catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt,rs);
}
return list;
}
private static final String SQL_GET_STUDENT_LIST_BY_PAGE =
"select * from (select a.*, rownum r from ("+
"select g.name gname, s.*,to_char(birthday,'yyyy-MM-dd') birthday1 from example_grade_tab g,example_student_tab s where g.gradeid=s.gradeid"+
") a where rownum <=?) where r >=?";
public List<Map<String,String>> getListByPage(int fromIndex,int toIndex){
PreparedStatement pstmt=null;
ResultSet rs=null;
List<Map<String,String>> list=new ArrayList<Map<String,String>>();//内存图?
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_GET_STUDENT_LIST_BY_PAGE);
pstmt.setInt(1,toIndex);//当前页末条记录索引
pstmt.setInt(2,fromIndex);//当前页首条记录索引
rs=pstmt.executeQuery();
Map<String,String> map=null;
while(rs.next()){
map=new HashMap<String,String>();
map.put("gname",rs.getString("gname"));
map.put("studentid", String.valueOf(rs.getInt("studentid")));
map.put("name",rs.getString("name"));
map.put("birthday",rs.getString("birthday1"));
map.put("sex",rs.getInt("sex")==0?"男":"女");
map.put("height",String.valueOf(rs.getFloat("height")));
map.put("description",rs.getString("description"));
list.add(map);
}
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt,rs);
}
return list;
}
private static final String SQL_GET_STUDENT_COUNT=
"select count(1) c from example_student_tab";
//通用应为:"select count(1) c from example_grade_tab a,example_student_tab b where a.grade"
public int getRecordCount(){
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
pstmt=DBManager.getConnection().prepareStatement(SQL_GET_STUDENT_COUNT);
rs=pstmt.executeQuery();
rs.next();
int c=rs.getInt("c");
return c;
}catch(Exception e){
e.printStackTrace();
}finally{
DBManager.clearup(pstmt,rs);
}
return 0;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
javaee oracle (172个子文件)
StudentDAO.class 7KB
VideoDAO.class 7KB
StudentDAOUtil.class 6KB
DbUtil.class 5KB
CategoryDAO.class 4KB
GradeDAO.class 4KB
StoredProcRunner.class 4KB
StoredProcRunner.class 4KB
VideoDAOUtil.class 4KB
DBManager.class 3KB
CategoryDAOUtil.class 3KB
LoginServlet.class 3KB
AuthenticationFilter.class 3KB
GradeDAOUtil.class 3KB
TestPathServlet.class 2KB
StudentEditServlet.class 2KB
StudentListServlet.class 2KB
VideoListServlet.class 2KB
TestManayListenerImpl.class 2KB
TestObjServlet.class 2KB
StringUtil.class 2KB
StudentUpdateServlet.class 2KB
VideoEditServlet.class 2KB
VideoUpdateServlet.class 2KB
StudentAddServlet.class 2KB
VideoAddServlet.class 2KB
VideoInAddServlet.class 2KB
CategoryAddAjaxServlet.class 2KB
CategoryEditServlet.class 2KB
GradeAddAjaxServlet.class 2KB
ExUserDAO.class 2KB
CharacterEncodingFilter.class 2KB
Student.class 2KB
CategoryUpdateServlet.class 2KB
GradeEditServlet.class 2KB
GradeUpdateServlet.class 2KB
XServlet.class 2KB
CategoryListServlet.class 2KB
StudentInAddServlet.class 2KB
BeanReuseHandler.class 2KB
Video.class 2KB
GradeListServlet.class 2KB
DbPool.class 2KB
CategoryAddServlet.class 2KB
User.class 2KB
GradeAddServlet.class 1KB
PageUtil.class 1KB
CategoryDeleteServlet.class 1KB
StudentDeleteServlet.class 1KB
GradeDeleteServlet.class 1KB
VideoDeleteServlet.class 1KB
BeanReuseProcessor.class 1KB
ExUser.class 1KB
ServletContextListenerImpl.class 1KB
Category.class 973B
Grade.class 953B
ServletRequestAttributeListenerImpl.class 788B
ServletContextAttributeListenerImpl.class 788B
YServlet.class 785B
HttpSessionAttributeListenerImpl.class 779B
HttpSessionActivationListenerImpl.class 690B
ServletRequestListenerImpl.class 650B
HttpSessionListenerImpl.class 642B
Constants.class 386B
.classpath 1KB
org.eclipse.wst.common.component 543B
org.eclipse.wst.jsdt.ui.superType.container 49B
ojdbc6.jar 1.9MB
proxool-cglib.jar 327KB
proxool-0.9.1.jar 196KB
tomcat-dbcp.jar 169KB
commons-dbutils-1.3.jar 40KB
commons-logging-1.0.4.jar 37KB
StudentDAO.java 8KB
StoredProcRunner.java 6KB
StoredProcRunner.java 6KB
VideoDAO.java 6KB
StudentDAOUtil.java 6KB
TeacherOnlineListener.java 4KB
DbUtil.java 4KB
CategoryDAO.java 4KB
GradeDAO.java 3KB
DbPool.java 3KB
VideoDAOUtil.java 3KB
DBManager.java 3KB
OnLineCountListener.java 2KB
TestPathServlet.java 2KB
CategoryDAOUtil.java 2KB
AuthenticationFilter.java 2KB
GradeDAOUtil.java 2KB
LoginServlet.java 2KB
TestObjServlet.java 2KB
PageUtil.java 2KB
StudentListServlet.java 2KB
BeanReuseHandler.java 2KB
StudentUpdateServlet.java 2KB
BeanReuseProcessor.java 2KB
TestManayListenerImpl.java 2KB
StudentAddServlet.java 2KB
StudentEditServlet.java 1KB
共 172 条
- 1
- 2
资源评论
- a6352136942013-01-05资源不是很好,内动用不上~~~
Sun_Boys
- 粉丝: 2
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功