📄 profile.java
字号:
package fengyun.Fastmail.beans;import java.util.*;import java.sql.*;public class Profile { private static BeansConstants CONST = BeansConstants.getInstance(); private String userid = null; private String username = null; private String location = null; private String zipcode = null; private String phone = null; private String year = null; private String month = null; private String day = null; private String cardNumber = null; private int gender = 0; private int occupation = 0; private int education = 0; private int province = 0; private int certificateType = 1; public void setUserid(String userid) { this.userid = userid; } public String getUserid() { return userid; } public void setUsername(String username) { this.username = username; } public String getUsername() { return username; } public void setLocation(String location) { this.location = location; } public String getLocation() { if (location != null) { return location; } else { return ""; } } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getZipcode() { if (zipcode != null) return zipcode; else return ""; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { if (phone != null) return phone; else return ""; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public String getCardNumber() { if (cardNumber != null) return cardNumber; else return ""; } public void setDay(String day) { this.day = day; } public String getDay() { if (day != null) return day; else return ""; } public void setYear(String year) { this.year = year; } public String getYear() { if (year != null) return year; else return ""; } public void setMonth(String month) { this.month = month; } public String getMonth() { if (month != null) return month; else return ""; } public void setEducation(int education) { this.education = education; } public int getEducation() { return education; } public void setOccupation(int occupation) { this.occupation = occupation; } public int getOccupation() { return occupation; } public void setProvince(int province) { this.province = province; } public int getProvince() { return province; } public void setCertificateType(int certificateType) { this.certificateType = certificateType; } public int getCertificateType() { return certificateType; } public void setGender(int gender) { this.gender = gender; } public int getGender() { return gender; } public int update() { if (!isValid()) return CONST.FORM_ERROR; char current = ' '; if (certificateType==1) { for (int i=0; i < cardNumber.length(); i++) { current = cardNumber.charAt(i); if (current<48 || current>57) return CONST.IDCARD_ERROR; } } else { for (int i=0; i < cardNumber.length(); i++) { current = cardNumber.charAt(i); if (current != '-' && !Character.isLetterOrDigit(current)) return CONST.STUDENT_ERROR; } } if (phone == null) phone = ""; String birthday = new String (year+"-"+month+"-"+day); String sql = "update profile set username = ?,gender = ?,birthday=?,certificateType=?," +
"cardNumber=?,province=?,education=?,occupation=?,phone=?,location=?,zipcode=? where userid=?"; try { Mysql mysql = new Mysql(sql);
mysql.setString(1,username);
mysql.setInt(2,gender);
mysql.setString(3,birthday);
mysql.setInt(4,certificateType);
mysql.setString(5,this.cardNumber);
mysql.setInt(6,this.province);
mysql.setInt(7,this.education);
mysql.setInt(8,this.occupation);
mysql.setString(9,this.phone);
mysql.setString(10,this.location);
mysql.setString(11,this.zipcode);
mysql.setString(12,this.userid); mysql.executeUpdate(); mysql.close(); } catch (Exception ex) { System.err.println("Profile.update():"); ex.printStackTrace(System.err); return CONST.SQL_ERROR; } return CONST.OK; } public boolean select() { try {
String sql = "select *,year(birthday) as year,month(birthday) as month,dayofmonth(birthday) as day from profile where userid = ?"; Mysql mysql = new Mysql(sql);
mysql.setString(1,userid); ResultSet rs = mysql.executeQuery(); boolean next = rs.next(); if (next) { username = rs.getString("username"); gender = rs.getInt("gender"); certificateType = rs.getInt("certificateType"); education = rs.getInt("education"); occupation = rs.getInt("occupation"); province = rs.getInt("province"); location = rs.getString("location"); zipcode = rs.getString("zipcode"); cardNumber = rs.getString("cardNumber"); phone = rs.getString("phone"); year = rs.getString("year"); month = rs.getString("month"); day = rs.getString("day"); } rs.close();
rs = null; mysql.close();
mysql = null; return next; } catch (Exception ex) { System.err.println("Profile.select():"); ex.printStackTrace(System.err); return false; } } public boolean isValid() { boolean valid = true; if (userid == null || userid.equals("")) valid = false; if (username == null || username.equals("")) valid = false; if (cardNumber == null || cardNumber.equals("")) valid = false; if (year == null || year.equals("") || month == null || month.equals("") || day == null || day.equals("")) valid = false; return valid; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -