在jsp中获取数据库数据
时间:2021-07-01 10:21:17
帮助过:18人阅读
"com.mysql.jdbc.Driver");
//加载mysql驱动
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "root", "3701211994812sls");
//localhost是本机地址,3306是端口号,最后是用户名和密码
Statement stmt=conn.createStatement();
//实例化Statement对象
String queryNumberSQL="SELECT * from p_user where username=‘"+name+"‘ and password=‘"+password+"‘"
;
ResultSet rs=stmt.executeQuery(queryNumberSQL);
//执行数据库查询操作并获取结果集
boolean flag=
false;
//初始化flag
if(rs.next()){
//判断结果
flag=
true;
session.setAttribute("UserName", name);
//将name的内容赋值给UserName
}
else{
flag=
false;
}
%>
在jsp中获取数据库数据
标签:result 获取 where driver boolean cal local 实例化 numbers