<!DOCTYPE html>
<html>
<head><title>查询信息的显示</title></head>
<body>
<script>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="com.mysql.jdbc.Driver" %>
<%@page import="java.sql.*" %>
<%
String user=request.getParameter("user");
String psd=request.getParameter("psd");
String msg="";
request.setCharacterEncoding("utf-8");//加载驱动程序
String driverName="com.mysql.jdbc.Driver";//数据库信息
String username = "root";//密码
String password = "2021210948";//数据库名
String dbName="customers";//将数据库信息字符串连接成为一个完整的url
String url="jdbc:mysql://localhost/"+dbName+"?user="+username+"&password="+password;
Class.forName(driverName).newInstance();//获得数据库连接
Connection conn=DriverManager.getConnection(url);//在这个数据库链接上创建一个命令对象
Statement stmt=conn.createStatement();
String sql = "select * from customers where name ='"+user+"' and psd = '"+psd+"'";
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
session.setAttribute("u",user);
response.sendRedirect("index.jsp");
}else {
response.sendRedirect("category.jsp?msg=false");
}
%>
</script>
</body>
</html>
2.这段报错是什么原因,怎么解决?
你要把错误截图截全贴出来
找不到数据库 customers
url都拼错了,端口呢
还有你这个单行注释不知道是从哪儿学的,全都没放对位置。 这个不是错,只是不规范