html页面获取mysql数据_怎样从HTML网页中获取SQL数据库里的数据

language="java"

contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"

%>

 管理中心


ID书名作者价格删除

// 数据库的名字

String dbName = "zap";

// 登录数据库的用户名

String username = "sa";

// 登录数据库的密码

String password = "123";

// 数据库的IP地址,本机可以用 localhost 或者 127.0.0.1

String host = "127.0.0.1";

// 数据库的端口,一般不会修改,默认为1433

int port = 1433;

String connectionUrl = "jdbc:sqlserver://" + host + ":" + port + ";databaseName=" + dbName + ";user=" + username

+ ";password=" + password;

//

//声明需要使用的资源

// 数据库连接,记得用完了一定要关闭

Connection con = null;

// Statement 记得用完了一定要关闭

Statement stmt = null;

// 结果集,记得用完了一定要关闭

ResultSet rs = null;

try {

// 注册驱动

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

// 获得一个数据库连接

con = DriverManager.getConnection(connectionUrl);

String SQL = "SELECT * from note";

// 创建查询

stmt = con.createStatement();

// 执行查询,拿到结果集

rs = stmt.executeQuery(SQL);

while (rs.next()) {

%>

" target="_blank">

" target="_blank">删除

}

} catch (Exception e) {

// 捕获并显示异常

e.printStackTrace();

} finally {

// 关闭我们使用过的资源

if (rs != null)

try {

rs.close();

} catch (Exception e) {}

if (stmt != null)

try {

stmt.close();

} catch (Exception e) {}

if (con != null)

try {

con.close();

} catch (Exception e) {}

}

%>

添加新纪录


版权声明:本文为weixin_34536454原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。