代码如下 : (把数据以表格形式输出 本人小白 哪位大侠能把完整的代码写出来呀 最好是可以添加、删除和显示表格的)
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java"%><%@ page import="com.mysql.jdbc.Driver"%><%@ page import="java.sql.*"%><%
//驱动程序名 String driverName = "com.mysql.jdbc.Driver"; //数据库用户名 String userName = "root"; //密码 String userPasswd = "root"; //数据库名 String dbName = "temp"; //表名 String tableName = "student"; //联结字符串 String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="
+ 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); //获得数据结果集合 ResultSetMetaData rmeta = rs.getMetaData(); //确定数据集的列数,亦字段数 int numColumns = rmeta.getColumnCount(); int count = 0;
%><!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
<link href='./css/logTemplate.css' type='text/css' rel='stylesheet'>
<title>java结业设计</title>
</head>
<body>
<div class='main'>
<div class='title bottomLine'><center>学生表</center></div>
<center> <%
while (rs.next()) {
count++;
%>
<div class='log'>
<div class='logInfo' style='color:blue'>
<%
out.print("学生ID:" + rs.getString("xsid") + " ");
out.print("学号:" + rs.getString("xh") + " ");
out.print("姓名:" + rs.getString("xm") + " ");
out.print("系ID:" + rs.getString("xid") + " ");
out.print("班级:" + rs.getString("bj") + " ");
%>
</div>
<div class='logBody'>
</div>
</div>
<%
}
%></center>
</div>
</body>
</html>
<%
rs.close(); statement.close(); connection.close(); %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java"%><%@ page import="com.mysql.jdbc.Driver"%><%@ page import="java.sql.*"%><%
//驱动程序名 String driverName = "com.mysql.jdbc.Driver"; //数据库用户名 String userName = "root"; //密码 String userPasswd = "root"; //数据库名 String dbName = "temp"; //表名 String tableName = "student"; //联结字符串 String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="
+ 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); //获得数据结果集合 ResultSetMetaData rmeta = rs.getMetaData(); //确定数据集的列数,亦字段数 int numColumns = rmeta.getColumnCount(); int count = 0;
%><!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
<link href='./css/logTemplate.css' type='text/css' rel='stylesheet'>
<title>java结业设计</title>
</head>
<body>
<div class='main'>
<div class='title bottomLine'><center>学生表</center></div>
<center> <%
while (rs.next()) {
count++;
%>
<div class='log'>
<div class='logInfo' style='color:blue'>
<%
out.print("学生ID:" + rs.getString("xsid") + " ");
out.print("学号:" + rs.getString("xh") + " ");
out.print("姓名:" + rs.getString("xm") + " ");
out.print("系ID:" + rs.getString("xid") + " ");
out.print("班级:" + rs.getString("bj") + " ");
%>
</div>
<div class='logBody'>
</div>
</div>
<%
}
%></center>
</div>
</body>
</html>
<%
rs.close(); statement.close(); connection.close(); %>
解决方案 »
- 单机下暂存数据如何处理?
- 有个关于web开发的疑问
- 请高手进来指点下谢谢
- jsp中使用bean的疑惑
- 在WEB工程中Log4j的配置文件log4j.properties应该放在哪个位置
- 请问,我要用控件指定一个‘文件夹’该如何去实现?
- SOS--> JBoss-4.0.2和Apache_2.0.54整合問題
- 请教个位大哥大姐jsp不能正常显示?
- (急!--在线等!)自定义了一个taglib,运行时出现的问题
- 我不知道如何安装tomcat,请赐教!!
- 关闭窗口执行HttpSessionListener中的sessionDestroyed方法
- Fckeditor 浏览服务器 出现the server didn't send back a proper XML response问题
<table style="border:1 solid blue;" rules="all" border="1" cellspacing="0" cellpadding="2">
<tr>
<td>学生ID</td>
<td>学号/td>
<td>姓名</td>
<td>姓名</td>
<td>姓名</td></tr>
<%
while (rs.next()) {
count++;
%>
<div class='log'>
<div class='logInfo' style='color:blue'>
<%
out.println("<tr>");
out.print("<td>" + rs.getString("xsid") + "</td>");
out.print(<td>" + rs.getString("xh") + "</td>");
out.print(<td>" + rs.getString("xm") + "</td>");
out.print(<td>" + rs.getString("xid") + "</td>");
out.print(<td>" + rs.getString("bj") + "</td>");
out.println("</tr>");
%>
</div>
<div class='logBody'></div>
</div>
<%
}
MVC分层设计
你最好先去找个例子研究一下