作者:手机用户2602889563 | 来源:互联网 | 2024-09-27 09:04
代码如下:(把数据以表格形式输出本人小白哪位大侠能把完整的代码写出来呀最好是可以添加、删除和显示表格的)<%@pagecontentTypetexthtmlpageEn
代码如下 : (把数据以表格形式输出 本人小白 哪位大侠能把完整的代码写出来呀 最好是可以添加、删除和显示表格的)
<%@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;
%>
学生表
<%
while (rs.next()) {
count++;
%>
<%
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") + " ");
%>
<%
}
%>
<%
rs.close();
statement.close();
connection.close();
%>
4 个解决方案