Package com.hdfs.util

Examples of com.hdfs.util.DBUtil


  }

  public boolean write(String username, String action, String filename,
      String pathname) {
    String sql = "INSERT INTO log (username, optime, action, filename, pathname) VALUES(?, ?, ?, ?, ?)";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      String optime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
          .format(new Date());
      pstmt.setString(2, optime);
      pstmt.setString(3, action);
      pstmt.setString(4, filename);
      pstmt.setString(5, pathname);
      if (pstmt.executeUpdate() > 0)
        return true;
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return false;
  }
View Full Code Here


public class UserDaoImpl implements UserDao {
  public User login(String username, String password) {
    User u = null;
    String sql = "SELECT * FROM user WHERE username=? and password=? ";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      pstmt.setString(2, password);
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        u = new User();
        u.setUsername(rs.getString(1));
        u.setPassword(rs.getString(2));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return u;
  }
View Full Code Here

    return u;
  }

  public boolean register(String username, String password) {
    String sql = "INSERT INTO user (username, password) VALUES(?, ?)";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      pstmt.setString(2, password);
      if (pstmt.executeUpdate() > 0) {
        return true;
      } else {
        return false;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return false;
  }
View Full Code Here

    return false;
  }
  public User getinfo(String username) {
    User u = null;
    String sql = "SELECT * FROM user WHERE username=?";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        u = new User();
        u.setUsername(rs.getString(1));
        u.setPassword(rs.getString(2));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return u;
  }
View Full Code Here

import com.hdfs.util.DBUtil;

public class PictureDaoImpl implements PictureDao {
  public boolean insert(String username, String pathname) {
    String sql = "INSERT INTO picture (username, pathname) VALUES(?, ?)";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      pstmt.setString(2, pathname);
      if (pstmt.executeUpdate() > 0) {
        return true;
      } else {
        return false;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return false;
  }
View Full Code Here

  }

  public ArrayList<String> get(String username) {
    ArrayList<String> paths = new ArrayList<String>();
    String sql = "SELECT pathname FROM picture WHERE username=?";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        String s = rs.getString(1);
        paths.add(s);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return paths;
  }
View Full Code Here

    return paths;
  }

  public boolean delete(String pathname) {
    String sql = "DELETE FROM picture WHERE pathname=?";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, pathname);
      if (pstmt.executeUpdate() > 0) {
        return true;
      } else {
        return false;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return false;
  }
View Full Code Here

public class LogDaoImpl implements LogDao {
  ArrayList<Log> logList = new ArrayList<Log>();

  public ArrayList<Log> read(String username) {
    String sql = "SELECT username, optime, action, filename, pathname FROM log WHERE username = ? order by optime desc";
    DBUtil util = new DBUtil();
    Connection conn = util.openConnection();
    try {
      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, username);
      ResultSet rs = pstmt.executeQuery();
      while (rs.next()) {
        Log log = new Log();
        log.setUsername(rs.getString(1));
        log.setDate(rs.getString(2).substring(0, 19));
        log.setAction(rs.getString(3));
        log.setFilename(rs.getString(4));
        log.setPathname(rs.getString(5));
        logList.add(log);
      }
      return logList;
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      util.closeConnection(conn);
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of com.hdfs.util.DBUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.