• JAVA日报


    javaweb(db)

    /*UserID,UserName,sex,idNumber,Phone,User;*/
    package dao;
    import dbutill.db;
    import java.sql.*;
    import java.util.ArrayList;
    import bean.*;
    public class UserDao {
    final String URL = "jdbc:mysql://localhost:3306/text?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
    final String USER = "root";
    final String PASSWORD = "123";
    final String DRIVER="com.mysql.cj.jdbc.Drive";
    public boolean addC(User t) throws ClassNotFoundException{
    String sql = "insert into t3(UserID,UserName,sex,idNumber,Phone,User,Password) values("+t.get("UserID")+","+t.get("UserName")+","+t.get("sex")+","+t.get("idNumber")+","+t.get("Phone")+","+t.get("User")+","+t.get("Password")+")";
    System.out.println(sql);
    Class.forName("com.mysql.cj.jdbc.Driver");
    Statement stat=null;
    Connection DBUtil=null;
    int act=0;
    try {
    DBUtil = DriverManager.getConnection(URL,USER,PASSWORD);
    } catch (SQLException e1) {
    e1.printStackTrace();
    }
    try {
    stat=DBUtil.createStatement();
    act=stat.executeUpdate(sql);
    }catch(Exception e) {
    e.printStackTrace();
    }finally {
    db.close(stat,DBUtil);
    }
    if(act>0) {
    return true;
    }else {
    return false;
    }
    }
    public boolean delC(String t) throws ClassNotFoundException{
    String sql="delete from t3 where UserID"+" ="+t;
    Class.forName("com.mysql.cj.jdbc.Driver");
    Statement stat=null;
    Connection DBUtil=null;
    int act=0;
    try {
    DBUtil = DriverManager.getConnection(URL,USER,PASSWORD);
    } catch (SQLException e1) {
    e1.printStackTrace();
    }
    try {
    stat=DBUtil.createStatement();
    act=stat.executeUpdate(sql);
    }catch(Exception e) {
    e.printStackTrace();
    }finally {
    db.close(stat,DBUtil);
    }
    if(act>0) {
    return true;
    }else {
    return false;
    }
    }
    public boolean gaiC(String id,String id1,String id3) throws ClassNotFoundException{
    String sql="update t3 set "+id+"='"+id1+"' where UserID='"+id3+"'";
    Class.forName("com.mysql.cj.jdbc.Driver");
    Statement stat=null;
    Connection DBUtil=null;
    int act=0;
    try {
    DBUtil = DriverManager.getConnection(URL,USER,PASSWORD);
    } catch (SQLException e1) {
    e1.printStackTrace();
    }
    try {
    stat=DBUtil.createStatement();
    act=stat.executeUpdate(sql);
    }catch(Exception e) {
    e.printStackTrace();
    }finally {
    db.close(stat,DBUtil);
    }
    if(act>0) {
    return true;
    }else {
    return false;
    }
    }
    @SuppressWarnings("null")
    public ArrayList<User> getAlluserinfos() throws ClassNotFoundException, SQLException{
    ArrayList<User> users=new ArrayList<>();
    PreparedStatement stat=null;
    Connection DBUtil=null;
    String sql2 = "select * from t3";
    Class.forName("com.mysql.cj.jdbc.Driver");
    try {
    DBUtil = DriverManager.getConnection(URL,USER,PASSWORD);
    } catch (SQLException e1) {
    e1.printStackTrace();
    }
    stat=DBUtil.prepareStatement(sql2);
    ResultSet rs = stat.executeQuery();

    while(rs.next()) {
    User user=new User();
    user.set("UserID",rs.getString("UserID"));
    user.set("UserName",rs.getString("UserName"));
    user.set("sex",rs.getString("sex"));
    user.set("idNumber",rs.getString("idNumber"));
    user.set("Phone",rs.getString("Phone"));
    user.set("User",rs.getString("User"));
    user.set("Password",rs.getString("Password"));
    users.add(user);
    }
    return users;

    }
    }
    /*UserID,
    UserName,
    sex,
    idNumber,
    Phone,
    User;*/

  • 相关阅读:
    JSP中的选择判断 C 标签 一般与 foreach循环一块使用
    python基础学习笔记(四)
    python基础学习笔记(五)
    python基础学习笔记(六)
    python基础学习笔记(三)
    python基础学习笔记(一)
    selenium使用Xpath定位之完整篇
    Selenium Python FirefoxWebDriver处理打开保存对话框
    Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表
    Selenium+Python:下载文件(Firefox 和 Chrome)
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14912452.html
Copyright © 2020-2023  润新知