20819101040楊榆作業五

 Yang Yu_發表於2020-10-08
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    Class.forName("com.mysql.jdbc.Driver");

    String url="jdbc:mysql://localhost:3306/book";
    Connection connection=DriverManager.getConnection(url,"root","root");

    String sql ="select * from user where username = ? and password = ?";
    // String sql="delete from user where id=3";
    //String sql = "update user set name=? where age=?";
    //String sql="insert into user(username,password,gender,age)values(?,?,?,?)";
    PreparedStatement ps =connection.prepareStatement(sql);

    ps.setString(1,request.getParameter("username"));
    ps.setString(2,request.getParameter("password"));
    

    ResultSet rs=ps.executeQuery();

    while (rs.next()){
        out.print(rs.getString("username")+"-"+rs.getString(3)+"<br>");
    }

%>
</body>
</html>

 

自己的電腦出現如下問題,程式碼無錯誤。

回機房進行測試。

相關文章