jsp使用jdb从读取个表格,报错不知道如何改
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录程序之验证页面</title>
</head>
<body>
<%!
public static final String DBDRIVER="com.mysql.jdbc.Driver";
public static final String DBURL="jdbc:mysql://127.0.0.1:3306/db_news2022";
public static final String DBUSER="root";
public static final String DBPASS="123456";
String[] userids;
String[] usernames;
String[] userpws;
%>
<%
Connection conn = null;
PreparedStatement ps = null;
ResultSet res = null;
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql = "select uid,uname,upassword from t_user";
ps = conn.prepareStatement(sql);
res = ps.executeQuery();
while(res.next()) {
int i=0;
userids[i] = res.getString("uid");
usernames[i] = res.getString("uname");
userpws[i] = res.getString("upassword");
i++;
}
%>
<%!
public String check(String userid, String userpw){
int i;
for(i=0;i<userids.length;i++) {
if(userids[i].equals(userid)) {
break;
}
}
if(i<userids.length) {
if(userpws[i].equals(userpw)) {
return usernames[i];
} else {
return "";
}
} else {
return "";
}
}
%>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String password = request.getParameter("password");
String remenber = request.getParameter("remenber");
String name;
Cookie[] cook;
if(!((name=check(id,password)).equals(""))) {
cook = request.getCookies();
int i;
boolean cookies_flag = false;
if(cook != null) {
for(i=0;i<cook.length;i++) {
if("Cookie2022".equals(cook[i].getName())) {
break;
}
}
if(i<cook.length) {
cookies_flag = false;
} else {
cookies_flag = true;
}
} else {
cookies_flag = true;
}
Cookie cookie;
if(remenber != null) {
if(cookies_flag) {
cookie = new Cookie("Cookie2022",id+"#"+password);
cookie.setMaxAge(45);
response.addCookie(cookie);
}
} else {
if(!cookies_flag) {
cookie = new Cookie("Cookie2022",id+"#"+password);
cookie.setMaxAge(0);
response.addCookie(cookie);
}
}
session.setAttribute("username", name);
session.setMaxInactiveInterval(60);
response.sendRedirect("login_success.jsp");
} else {
response.sendRedirect("login_failure.jsp");
}
%>
</body>
</html>
这是数据库
这个是错误