zoukankan      html  css  js  c++  java
  • jsp中使用的mysql笔记

    public static Connection getConnection() throws SQLException,
    java.lang.ClassNotFoundException {
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/usermanager?useUnicode=true&characterEncoding=gbk";
    String username = "root";
    String password = "123";
    Connection con = DriverManager.getConnection(url, username, password);
    return con;
    }
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/html");
    res.setCharacterEncoding("utf-8");
    String name=req.getParameter("name");
    String pw=req.getParameter("pw");
    name=new String(name.getBytes("ISO-8859-1"),"utf-8");
    pw=new String(pw.getBytes("ISO-8859-1"),"utf-8");
    try {
    Connection con = getConnection();
    Statement sql_statement = con.createStatement();
    String query = "select * from user where uname=? and password=?";
    PreparedStatement ps=con.prepareStatement(query);
    ps.setString(1, name);ps.setString(2, pw);
    ResultSet result = ps.executeQuery();

    con.close();
    } catch (java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException");
    System.err.println(e.getMessage());
    } catch (SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    }
    }

  • 相关阅读:
    怎么加载用户自定义控件
    一个C#委托的示例
    signed add
    避免QuartusII中将没有进行定义的信号自动生成wrie类型
    serial_to_parallel
    用modelsim仿真——对文件的操作
    base of logic
    blocking PK nonblocking
    parallel to serial
    使用signalTapII看综合掉的wrie和register的值
  • 原文地址:https://www.cnblogs.com/javaxiu/p/3539818.html
Copyright © 2011-2022 走看看