JDBC是一种用于执行SQL语句的API,由一组类与接口组成,通过调用这些类和接口所提供的方法,可以使用标准的SQL语言来存取数据库中的数据。
String driverName = "com.mysql.jdbc.Driver"; String dbName = "students"; String url1 = "jdbc:mysql://localhost:3306/"+dbName; String url3 = "&useUnicode = true & characterEncoding = UTF-8"; try{ Class.forName(driverName); Connection conn = DriverManager.getConnection(url1,"root","123456"); String sql = "select pwd from user where ID = ?"; PreparedStatement pstmt = conn.prepareStatement(sql); String ID = request.getParameter("ID"); pstmt.setString(1,ID); ResultSet rs = pstmt.executeQuery(); String pwd = ""; while(rs.next()) pwd = rs.getString("pwd"); if(pwd.equals("")) {out.print("用户不存在");} else { String Dpwd = request.getParameter("ipwd"); rs.close(); pstmt.close(); conn.close(); if(pwd.equals(Dpwd)){ %> <jsp:forward page = "access.jsp"></jsp:forward> <% }else {out.print("密码错误");%> <%}}%> <a href = "login.jsp">返回登陆</a> <%}catch(SQLException e) { e.printStackTrace(); }%