自己从网上找的用过jsp显示数据库某个表的信息的代码,开始的一个表可以显示,但是后面新建的一个表属性多了,就不成功,希望大神帮忙解决一下 ,尽可能详细的解决方法

Starry_lin 2020-05-19 09:16:24
之前的表只显示三个,现在的表要显示六个,初学者希望帮我解决一下
显示的代码如下:
find.jsp
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 参考博文 http://blog.csdn.net/believejava/article/details/39111823 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>验证成功界面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
table {
border: 2px #CCCCCC solid;
width: 360px;
}
td,th {
height: 30px;
border: #CCCCCC 1px solid;
}
</style>
</head>
<body>
界面表单提交跳转成功 <br>
<a href="index.jsp">返回</a>
<%
//驱动程序名
String driverName = "com.mysql.jdbc.Driver";
//数据库用户名
String userName = "root";
//密码
String userPasswd = "ax191823503";
//数据库名
String dbName = "zhbit";
//表名
String tableName = "book";
//联结字符串
String url = "jdbc:mysql://localhost:3306/" + dbName + "?userid="
+ userName + "&password=" + userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "SELECT * FROM " + tableName;
ResultSet rs = statement.executeQuery(sql);
%>
<br>
<br>
<table align="center">
<tr>
<th>
<%
out.print("书籍编号");
%>
</th>
<th>
<%
out.print("书名");
%>
</th>
<th>
<%
out.print("作者");
%>
</th>
<th>
<%
out.print("类别");
%>
</th>
<th>
<%
out.print("数量");
%>
</th>
<th>
<%
out.print("价格");
%>
</th>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td>
<%
out.print(rs.getString(1));
%>
</td>
<td>
<%
out.print(rs.getString(2));
%>
</td>
<td>
<%
out.print(rs.getString(3));
%>
</td>
<td>
<%
out.print(rs.getString(4));
%>
</td>
<td>
<%
out.print(rs.getString(5));
%>
</td>
<td>
<%
out.print(rs.getString(6));
%>
</td>
</tr>
<%
}
%>
</table>
<div align="center">
<br> <br> <br>
<%
out.print("已上架的书籍信息如上-");
%>
</div>
<%
rs.close();
statement.close();
connection.close();
%>
</body>
</html>
...全文
34 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧