JSP链接mysql登陆验证失败是哪里错了?在线等
答案:2 悬赏:50 手机版
解决时间 2021-01-03 12:03
- 提问者网友:原来太熟悉了会陌生
- 2021-01-02 23:46
<%
request.setCharacterEncoding("utf-8");
String name=request.getParameter("txtname");
String password=request.getParameter("txtpwd");
Class.forName("org.gjt.mm.mysql.Driver");//加载驱动程序类型
String url="jdbc:mysql://localhost:3306/newone?user=root&password=123&useUnicode=true&characterEncoding=utf-8";//设置连接数据库参数
Connection conn=DriverManager.getConnection(url);//创建数据库连接
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users where name='"+name+"' and password='"+password+"'";
System.out.print(sql);
int result=stmt.executeUpdate(sql);//执行SQL语句
if(result!=0){
response.sendRedirect("gldenlu.jsp");//执行插入成功跳转
}else{
response.sendRedirect("addBooks.jsp");//执行插入失败跳转
}
%>