| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 610 人关注过本帖
标题:下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码对不? ...
只看楼主 加入收藏
lysylrh
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-8-1
结帖率:100%
收藏
 问题点数:0 回复次数:2 
下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码对不?
package sms.bean;

import sms.db.DBAccess;
import java.sql.*;
import
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) {
         = 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.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 
2011-08-02 20:14
bcyu
Rank: 2
等 级:论坛游民
帖 子:39
专家分:56
注 册:2011-5-9
收藏
得分:0 
学习中,看看..............................
2011-08-16 01:24
xmlz
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:294
专家分:1392
注 册:2010-8-29
收藏
得分:0 
试下就知道了,又长字又小,看着多累
2011-08-17 12:32
快速回复:下面是我的studentbean,我用的数据库是oracle,请高手看看,以下代码 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016397 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved