设为首页 加入收藏

TOP

Java中date与Jsp中date交互
2014-10-26 19:30:03 来源: 作者: 【 】 浏览:80
Tags:Java date Jsp 交互

  Judge.java:


  package com.goodhope.regist;


  import java.sql.Connection;


  import java.sql.DriverManager;


  import java.sql.ResultSet;


  import java.sql.SQLException;


  import java.sql.Statement;


  import java.util.Date;


  public class Judge {


  Statement stmt;


  ResultSet rs;


  public void init() {


  try {


  Class.forName("org.postgresql.Driver");


  String url = "jdbc:postgresql://localhost:5432/postgres";


  Connection con = DriverManager.getConnection(url, "postgres",


  "pair36");


  stmt = con.createStatement();


  } catch (Exception e) {


  e.printStackTrace();


  }


  }


  public boolean IfExit(String username) {


  Boolean a = false;


  init();


  String sql = "select name from cas where name='" + username + "'";


  try {


  rs = stmt.executeQuery(sql);


  } catch (SQLException e) {


  e.printStackTrace();


  }


  try {


  a = rs.next();


  } catch (SQLException e) {


  e.printStackTrace();


  }


  return a;


  }


  public void InsetIntoTable(String name, String pwd, Date birthday) {


  init();


  String sql = "insert into cas (name,password,birthday) values ('"


  + name + "','" + pwd + "',to_date('" + birthday


  + "','yyyy-mm-dd'))";


  try {


  stmt.execute(sql);


  } catch (SQLException e) {


  e.printStackTrace();


  }


  }


  }


  Regist.java


  package com.goodhope.regist;


  import java.sql.Date;


  import com.opensymphony.xwork2.ActionSupport;


  public class Regist extends ActionSupport {


  private static final long serialVersionUID = -5254042367980236169L;


  private String username;


  private String password;


  private Date birthday;


  public String getUsername() {


  return username;


  }


  public void setUsername(String username) {


  this.username = username;


  }


  public String getPassword() {


  return password;


  }


  public void setPassword(String password) {


  this.password = password;


  }


  public Date getBirthday() {


  return birthday;


  }


  public void setBirthday(Date birthday) {


  this.birthday = birthday;


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java文件加密-spring属性文件加密 下一篇JAVA实现AES加密

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: