index.jsp
<body>
<form action="check.jsp" method="post">
用户名<input type="text" name="uname"><br/>
密码<input type="password" name="upwd"><br/>
<input type="submit" value="登录"><br/>
</form>
</body>
check.jsp
// 导入驱动,加载具体驱动类
Class.forName("com.mysql.cj.jdbc.Driver");
// 与数据库建立连接
connection = DriverManager.getConnection(URL, USERNAME, PSW);
// 发送sql,执行增、删、改
stmt = connection.createStatement();
String name=request.getParameter("uname");
String pwd=request.getParameter("upwd");
//错误写法1://String sql = "select count(*) from user where name=' "+name+" ' and pwd=' "+pwd+" ' ";
String sql = "select count(*) from user where uname=' "+name+" ' and upwd=' "+pwd+" ' ";
// =左边的uname是数据库中定义的字段名,右边的name是上面的String name获取的用户输入的值
//错误写法2://String sql = "select name,pwd from user where name='name' and pwd='pwd' ";
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。