<%@ page language="java" import="java.sql.*" contentType="text/html" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body{
background-color: cyan;
}
</style>
</head>
<body>
<%
String driverName = "com.mysql.jdbc.Driver"; //驱动程序名
String userName = "root"; //数据库用户名
String userPwd = "123456"; //密码
String dbName = "shop"; //数据库名
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2 ="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=utf-8";
String url =url1+url2+url3; //形成带数据库读写编码的数据库连接字
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);
String sql="select * from cart";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
out.println(rs.getString("commodity"));
out.println(rs.getString("price"));%>
<br><%
}
if(stmt!=null){ stmt.close(); }
if(conn!=null){ conn.close(); }
%>
</body>
</html>
数据输出
最新推荐文章于 2023-03-21 21:07:22 发布