当前位置: 代码迷 >> Java Web开发 >> 下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码对不? ...
  详细解决方案

下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码对不? ...

热度:197   发布时间:2011-08-02 20:14:25.0
下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码对不?
package sms.bean;

import sms.db.DBAccess;
import java.sql.*;
import java.io.Serializable;
import java.util.ArrayList;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class StudentBean implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    public StudentBean() {
    }

    private String classId;
    private String collegeId;
    private String password;
    private String studentId;
    private String name;
    private String comeFrom;
    private String sex;
    private String collegeName;
    private int currentTerm;
    private String age;
    public String getClassId() {
        return classId;
    }

    public String getAge() {
       return age;
   }

   public void setAge(String age) {
        this.age = age;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setCollegeId(String collegeId) {
        this.collegeId = collegeId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setComeFrom(String comeFrom) {
        this.comeFrom = comeFrom;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public void setCollegeName(String collegeName) {
        this.collegeName = collegeName;
    }

    public void setCurrentTerm(int currentTerm) {
        this.currentTerm = currentTerm;
    }


    public String getCollegeId() {
        return collegeId;
    }

    public String getPassword() {
        return password;
    }

    public String getStudentId() {
        return studentId;
    }

    public String getName() {
        return name;
    }

    public String getComeFrom() {
        return comeFrom;
    }

    public String getSex() {
        return sex;
    }

    public String getCollegeName() {
        return collegeName;
    }

    public int getCurrentTerm() {
        return currentTerm;
    }


    public static void main(String[] args) {
        new StudentBean();
    }

    public StudentBean queryStuInfo(String stuId, String password) {
        DBAccess dba = new DBAccess();
        String sql = "select stu_id,name,password,class_id,college_id,enroll_time from student_info where stu_id = " +
                     stuId + " and password=" + password;
        dba.getConnection();
        
        @SuppressWarnings("static-access")
        String currentDate = dba.getSysDate().trim();
        String currentYear = currentDate.substring(0,4).trim();
        String currentMonth = currentDate.substring(5,7).trim();
        if(currentMonth.startsWith("0")){
          currentMonth = currentMonth.substring(1,2);
        }
        StudentBean stuBean = null;
        ResultSet rs = dba.query(sql);
        try {
            if (rs != null && rs.next()) {
                stuBean = new StudentBean();
                stuBean.setStudentId(rs.getString("stu_id"));
                stuBean.setName(rs.getString("name"));
                stuBean.setPassword(rs.getString("password"));
                stuBean.setClassId(rs.getString("class_id"));
                stuBean.setCollegeId(rs.getString("college_id"));
                String enrollYear = rs.getString("enroll_time").trim().substring(0,4);
                int enrollYearInt = Integer.parseInt(enrollYear);
                int currentYearInt = Integer.parseInt(currentYear);
                int currentMonthInt = Integer.parseInt(currentMonth);
                if(enrollYearInt > currentYearInt){
                  stuBean.setCurrentTerm(1);
                }else{
                  int temp = (currentYearInt-enrollYearInt)*2;
                  if(currentMonthInt > 7){
                      temp  += 1;
                  }
                  stuBean.setCurrentTerm(temp);
                }
                return stuBean;
            } else {
                return null;
            }
        } catch (SQLException ex) {
            return null;
        } finally {
            dba.closeConnection();
        }
    }

    public boolean checkPwd(String stuId, String password) {
        DBAccess dba = new DBAccess();
        String sql = "select stu_id,name,password,class_id,college_id,enroll_time from student_info where stu_id = " +
                     stuId + " and password=" + password;
        dba.getConnection();

        ResultSet rs = dba.query(sql);
        try {
            if (rs != null && rs.next()) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            return false;
        } finally {
            dba.closeConnection();
        }
    }


    public ArrayList<StudentBean> queryClassStudents(String classId) {
        DBAccess dba = new DBAccess();
        String sql = "select a.stu_id,a.name,a.password,a.class_id,a.college_id ,a.come_from,a.sex,a.age,b.name collegename from student_info a,college_info b where a.college_id=b.college_id and a.class_id = '" +
                     classId +"';";
        ArrayList<StudentBean> arrayList = new ArrayList<StudentBean>();
        try {
            dba.getConnection();
            ResultSet rs = dba.query(sql);
            while (rs.next()) {
                StudentBean stuBean = new StudentBean();
                stuBean.setClassId(rs.getString("class_id"));
                stuBean.setCollegeId("college_id");
                stuBean.setComeFrom(rs.getString("come_from"));
                stuBean.setName(rs.getString("name"));
                stuBean.setStudentId(rs.getString("stu_id"));
                stuBean.setSex(rs.getString("sex"));
                stuBean.setCollegeName(rs.getString("collegename"));
                stuBean.setAge(rs.getString("age"));
                arrayList.add(stuBean);
            }
            return arrayList;
        } catch (SQLException ex) {
            ex.printStackTrace();
            return null;
        } finally {
            dba.closeConnection();
        }
    }

    public int modifyPassword(String studentId, String oldPassword,
                              String newPassword) {
        DBAccess dba = new DBAccess();
        String sql = "select password from student_info where stu_id =" +
                     studentId;
        String sql2 = "update student_info set password=" + newPassword +
                      " where stu_id=" + studentId;
        try {
            dba.getConnection();
            ResultSet rs = dba.query(sql);
            if (rs != null && rs.next()) {
                if (!oldPassword.equals(rs.getString("password"))) {
                    return 0;
                }
                int i = dba.executeSql(sql2);
                if (i > 0) {
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return -2;
            }
        } catch (Exception ex) {
            return -1;
        } finally {
            dba.closeConnection();
        }
    }
}
搜索更多相关主题的帖子: oracle  数据库  Copyright  version  private  

----------------解决方案--------------------------------------------------------
学习中,看看..............................
----------------解决方案--------------------------------------------------------
试下就知道了,又长字又小,看着多累
----------------解决方案--------------------------------------------------------
  相关解决方案