📄 addressaction.java
字号:
package fengyun.Fastmail.beans;import java.io.PrintStream;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;public class AddressAction { private String action = null; private int id = 0; private String regdate = null; private String userid = null; private String year = null; private String month = null; private String day = null; private String username = null; private String gender = null; private String location = null; private String zipcode = null; private String bpcode = null; private String handset = null; private String phone = null; private String email = null; private String homepage = null; private String birthday = null; public void setAction(String act) { action = act; } public String getAction() { return action; } public void setId(int pid) { id = pid; } public int getId() { return id; } public String getRegdate() { return regdate; } 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 setDay(String day) { this.day = day; } public String getDay() { return day; } public void setYear(String year) { this.year = year; } public String getYear() { return year; } public void setMonth(String month) { this.month = month; } public String getMonth() { return month; } public void setGender(String gender) { this.gender = gender; } public String getGender() { return gender; } public void setLocation(String location) { this.location = location; } public String getLocation() { return location; } public void setHomepage(String homepage) { this.homepage = homepage; } public String getHomepage() { return homepage; } public void setEmail(String email) { this.email = email; } public String getEmail() { return email; } public void setHandset(String handset) { this.handset = handset; } public String getHandset() { return handset; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return phone; } public void setBpcode(String bpcode) { this.bpcode = bpcode; } public String getBpcode() { return bpcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getZipcode() { return zipcode; } public String getBirthday() { return birthday; } public boolean execute() { if (action == null) { return false; } else if (action.equals("delete")) { delete(); return true; } else if (action.equals("update")) { update(); return true; } else if (action.equals("insert")) { insert(); return true; } else { return false; } } public void select() {
try
{
String sql = "select *,year(birthday) as year,month(birthday) as month,dayofmonth(birthday) as day from address where id = ? and userid = ?";
Mysql mysql = new Mysql(sql);
mysql.setInt(1, id);
mysql.setString(2, userid);
ResultSet rs = mysql.executeQuery();
if(rs.next())
{
id = rs.getInt("id");
userid = rs.getString("userid");
username = rs.getString("username");
email = rs.getString("email");
location = rs.getString("location");
bpcode = rs.getString("bpcode");
zipcode = rs.getString("zipcode");
phone = rs.getString("phone");
handset = rs.getString("handset");
homepage = rs.getString("homepage");
gender = rs.getString("gender");
year = rs.getString("year");
month = rs.getString("month");
day = rs.getString("day");
birthday = rs.getString("birthday");
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy.MM.dd");
regdate = simpledateformat.format(rs.getDate("regdate"));
}
rs.close();
rs = null;
mysql.close();
mysql = null;
}
catch(Exception exception)
{
System.err.println("Address.select():");
exception.printStackTrace(System.err);
} } public void insert() {
if(year == null || month == null || day == null)
birthday = "1900-00-00";
else
birthday = new String(year + "-" + month + "-" + day);
if(homepage == null)
homepage = "";
if(phone == null)
phone = "";
if(bpcode == null)
bpcode = "";
if(handset == null)
handset = "";
if(zipcode == null)
zipcode = "";
if(location == null)
location = "";
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
String regdate = simpledateformat.format(new Date());
String sql = "insert into address (userid,regdate,username,email,gender,birthday,homepage,location,zipcode,phone,bpcode,handset) values (?,?,?,?,?,?,?,?,?,?,?,?)";
try
{
Mysql mysql = new Mysql(sql);
mysql.setString(1, userid);
mysql.setString(2, regdate);
mysql.setString(3, username);
mysql.setString(4, email);
mysql.setString(5, gender);
mysql.setString(6, birthday);
mysql.setString(7, homepage);
mysql.setString(8, location);
mysql.setString(9, zipcode);
mysql.setString(10, phone);
mysql.setString(11, bpcode);
mysql.setString(12, handset);
mysql.executeUpdate();
mysql.close();
mysql = null;
}
catch(Exception exception)
{
System.err.println("Address.insert():");
exception.printStackTrace(System.err);
}
} public void update() {
birthday = new String(year + "-" + month + "-" + day);
String sql = "update address set regdate=NOW(),username=?,email=?,gender=?,birthday=?,homepage=?,location=?,zipcode=?,phone=?,bpcode=?,handset=? where id=? and userid=?";
try
{
Mysql mysql = new Mysql(sql);
mysql.setString(1, username);
mysql.setString(2, email);
mysql.setString(3, gender);
mysql.setString(4, birthday);
mysql.setString(5, homepage);
mysql.setString(6, location);
mysql.setString(7, zipcode);
mysql.setString(8, phone);
mysql.setString(9, bpcode);
mysql.setString(10, handset);
mysql.setInt(11, id);
mysql.setString(12, userid);
mysql.executeUpdate();
mysql.close();
mysql = null;
}
catch(Exception exception)
{
System.err.println("Address.update():");
exception.printStackTrace(System.err);
} } public void delete() { try
{
String sql = "delete from address where id = ? and userid = ?";
Mysql mysql = new Mysql(sql);
mysql.setInt(1, id);
mysql.setString(2, userid);
mysql.executeUpdate();
mysql.close();
mysql = null;
}
catch(Exception exception)
{
System.err.println("Address.delete():");
exception.printStackTrace(System.err);
} } public boolean isValid() { boolean valid = false; if (action == null) { valid = false; } else if (action.equals("select")) { if (id > 0 && userid != null && !userid.equals("")) valid = true; } else if (action.equals("delete")) { if (id > 0 && userid != null && !userid.equals("")) valid = true; } else if (action.equals("insert")) { if (userid != null && !userid.equals("") && username != null && !username.equals("") && email != null && !email.equals("")) valid = true; } else if (action.equals("update")) { if (id > 0 && userid != null && !userid.equals("") && username != null && !username.equals("") && email != null && !email.equals("")) valid = true; } else { valid = false; } return valid; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -