介绍资料库内容 : 数据库 « JSP技术 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » JSP技术 » 数据库屏幕截图 
介绍资料库内容


<%@page import="java.sql.*"%>
<html>
<head>
<title>Presenting database content</title>
</head>
<body>
<h1>Address List</h1>
<%
    Connection conn = null;
    ResultSet result = null;
    Statement stmt = null;
    ResultSetMetaData rsmd = null;

    try {
      Class c = Class.forName("com.mysql.jdbc.Driver");
    }
    catch (Exception e) {
      System.out.println("Error occurred " + e);
     }
     try {
       conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ADDRESS");
     }
     catch (SQLException e) {
        System.out.println("Error occurred " + e);
     }
     try {
        stmt = conn.createStatement();
        result = stmt.executeQuery("SELECT * FROM AddressList");
     }
     catch (SQLException e) {
         System.out.println("Error occurred " + e);
      }

     int columns=0;
     try {
       rsmd = result.getMetaData();
       columns = rsmd.getColumnCount();
     }
     catch (SQLException e) {
        System.out.println("Error occurred " + e);
     }
%>
<table width="90%" border="1">
  <tr>
  <% // write out the header cells containing the column labels
     try {
        for (int i=1; i<=columns; i++) {
             out.write("<th>" + rsmd.getColumnLabel(i"</th>");
        }
  %>
  </tr>


  <% // now write out one row for each entry in the database table
        while (result.next()) {
           out.write("<tr>");
           for (int i=1; i<=columns; i++) {
             out.write("<td>" + result.getString(i"</td>");
           }
           out.write("</tr>");
        }

        // close the connection and the statement
        stmt.close();
        conn.close();
     // end of the try block
     catch (SQLException e) {
        System.out.println("Error " + e);
     }
     // ensure everything is closed
   finally {
    try {
      if (stmt != null)
       stmt.close();
      }  catch (SQLException e) {}
      try {
       if (conn != null)
        conn.close();
       catch (SQLException e) {}
   }

   %>
</table>
</body>
</html>


           
       
Related examples in the same category
1. JSP的数据库演示
2. JSP的数据库查询
3. 第一个JSP数据库
4. 浏览数据库表
5. 加入表
6. 填补表
7. 显示数据库中的表
8. 从数据库选择记录的条件
9. 浏览数据库表2
10. 应用表数据
11. 创建表
12. 访问数据库表字段
13. 从数据库提取数据
14. JSTL:交易的JSP技术
15. 使用结果对象
16. JSP技术中调用一个存储过程
17. 数据库内容介绍使用标签
18. 在JSP获得连接
19. 使用DataSource
20. 使用事务
21. 更新的数据库使用SQL :更新标记
22. 使用一个预先的DataSource
23. 使用SortedMap
24. 使用executeUpdate创造新的地址
25. 获取数据库连接
26. JSP中使用数据库
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.