JSP中实现数据库的增删改查
程序员文章站
2022-04-01 19:41:30
在home.jsp中查询数据库信息<% //加载数据库驱动 Class.forName("com.mysql.jdbc.Driver"); //建立数据库连接 String url = "jdbc:mysql://localhost:3306/book"; Connection connection = DriverManager.getConnection(url,"root","root"); //创建Stateme...
在home.jsp中查询数据库信息
<%
//加载数据库驱动
Class.forName("com.mysql.jdbc.Driver");
//建立数据库连接
String url = "jdbc:mysql://localhost:3306/book";
Connection connection = DriverManager.getConnection(url,"root","root");
//创建Statement对象
Statement stmt = connection.createStatement();
String sql = "select * from user";
//执行查询 返回结果集
ResultSet rs = stmt.executeQuery(sql);
//遍历结果集数据
while (rs.next())
{
out.print(rs.getString("username")+"-"+rs.getString(3)+"<br>");
}
%>
查询结果截图
本文地址:https://blog.csdn.net/qq_48567897/article/details/108939949