花溪★流年 2022-05-01 22:34 采纳率: 61.5%
浏览 15
已结题

jdbc读取一个表格,出现错误

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>

这是数据库

img


这个是错误

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月9日
    • 创建了问题 5月1日

    悬赏问题

    • ¥15 急,ubuntu安装后no caching mode page found等
    • ¥15 联想交换机NE2580O/NE1064TO安装SONIC
    • ¥15 防火墙的混合模式配置
    • ¥15 Ubuntu不小心注销了要怎么恢复啊
    • ¥15 win10电脑安装完plcsim advanced4.0运行时为什么会提示找不到虚拟网卡
    • ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
    • ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
    • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
    • ¥15 python怎么在已有视频文件后添加新帧
    • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,