JdonFramework应用案例:新闻发布系统

05-03-12 banq
http://www.jdon.com/jdonframework/news.htm

欢迎批评指正,也欢迎更多程序员加入完善该系统。

         

zhangmingjing
2005-03-14 15:46
请问登录界面的用户名、密码是多少?

dkmilk
2005-03-14 22:10

 public User getUserByName(String username) throws Exception {
      logger.debug(" getUserByName " + username);
      Connection c = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      User ret = null;
      try {
        String GET_USER =
            "select  * from t_user where username = ?";
        c = dataSource.getConnection();
        ps = c.prepareStatement(GET_USER,
                                ResultSet.TYPE_SCROLL_INSENSITIVE,
                                ResultSet.CONCUR_READ_ONLY);
        ps.setString(1, username);
        rs = ps.executeQuery();
        if (rs.first()) {
          ret = new User();
          ret.setUserName(username);
          ret.setUserId(rs.getString("userid"));
          ret.setPassword(rs.getString("password"));

        }
      }
      catch (SQLException se) {
        throw new Exception("SQLException: " + se.getMessage());
      }
      finally {
        if (rs != null) {
          rs.close();
        }
        if (ps != null) {
          ps.close();
        }
        if (c != null) {
          c.close();
        }
      }
      return ret;
  }

这样写怎么看怎么感觉怪异。

ahbbxie
2005-03-16 14:39
>

>

> public User getUserByName(String username) throws
> Exception {
> logger.debug(" getUserByName " + username);
> Connection c = null;
> PreparedStatement ps = null;
> ResultSet rs = null;
> User ret = null;
> try {
> String GET_USER =
> "select  * from t_user where username =
> username = ?";
> c = dataSource.getConnection();
> ps = c.prepareStatement(GET_USER,
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ResultSet.TYPE_SCROLL_INSENSITIVE,
> 
> 
> 
> 
> 
> 
> 
> 
> ResultSet.CONCUR_READ_ONLY);
> ps.setString(1, username);
> rs = ps.executeQuery();
> if (rs.first()) {
> ret = new User();
> ret.setUserName(username);
> ret.setUserId(rs.getString("userid"));
> ret.setPassword(rs.getString("password"));
> 
> }
> }
> catch (SQLException se) {
> throw new Exception("SQLException: " +
> on: " + se.getMessage());
> }
> finally {
> if (rs != null) {
> rs.close();
> }
> if (ps != null) {
> ps.close();
> }
> if (c != null) {
> c.close();
> }
> }
> return ret;
> }

>

> 这样写怎么看怎么感觉怪异。

hehe 用一个模板模式就可以就这些数据库通用操作封装起来,怎么banq没想起来啊。

banq
2005-03-19 16:20
>界面的用户名、密码是你插入数据库的数据,缺省是admin 123

模板模式建议很好,会加入的,其他getDatas基本都已经使用模板。

猜你喜欢
6Go 1 2 3 4 ... 6 下一页