📄 select3.txt
字号:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<HTML>
<head>
<title>多表查询</title>
</head>
<BODY>
<%
//驱动程序名、数据库用户名、密码、数据库名、表名
String driverName="com.mysql.jdbc.Driver";
String username="root";
String password="yesterdayn";
String dbName="study";
//连接字符串
String url="jdbc:mysql://localhost/"+dbName+"?characterEncoding=GBK";
try{
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//建立同数据库的连接对象
Connection connection=DriverManager.getConnection(url,username,password);
Statement statement = connection.createStatement();
//发送执行SQL语句
String sql="SELECT ordering.name,product.* FROM ordering,product WHERE ordering.pdm=product.pdm";
ResultSet rs = statement.executeQuery(sql);
out.print("多表查询成功!<BR>");
out.print("<TABLE BORDER=1 bordercolorlight=#000000 >");
out.print("<TR><TD width=40>序号</TD>");
out.print("<TD width=60>客户</TD>");
out.print("<TD width=80>商品名称</TD>");
out.print("<TD width=60>品牌</TD>");
out.print("<TD width=80>价格/元</TD></TR>");
int i=1;
while(rs.next())
{
out.print("<TR>");
out.print("<TD>"+i+"</TD>");
out.print("<TD>"+rs.getString("ordering.name")+"</TD>");
out.print("<TD>"+rs.getString("product.pname")+"</TD>");
out.print("<TD>"+rs.getString("provider")+"</TD>");
out.print("<TD>"+rs.getString("price")+"</TD>");
out.print("</TR>");
}
out.print("</TABLE>");
rs.close();
statement.close();
connection.close();
}
catch(SQLException e)
{
out.print(e.toString());
}
%>
</HTML>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -