一聚教程网:一个值得你收藏的教程网站

热门教程

JSP从数据库中导出数据并输出生成XML文件

时间:2022-06-29 02:53:04 编辑:袖梨 来源:一聚教程网

JSP从数据库教程中导出数据并输出生成XML文件
/*
数据库结构

create table userTable01(
    user_id int(4) NOT NULL primary key auto_increment,
    user_name varchar(40),
    user_password varchar(40),
    user_true_name varchar(40),
    user_age int, user_sex varchar(2),
    user_address varchar(80),
    user_telphone varchar(20),
    add_time datetime
);
insert into usertable01 (
        user_name,
        user_password,
        user_true_name,
        user_age,
        user_sex,
        user_address,
        user_telphone,
        add_time)
       values ('wgy','123123','gavin.wang','23','M','sdfg','321321',now());

//xml文档结构


-
-
  1
  wgy
  123123
  www.111com.net
  23
  M
 
sdfg

  321321
  2010-01-06
 

 

 


*/

<%@ page contentType = "text/xml;charset =gb2312" %>
<%@ page import = "java.sql.*" %>


<%
    Connection con = null;
    Statement sql = null;
    ResultSet rs = null;
   
    try
    {
        String url = "jdbc:mysql教程://localhost:3306/test"; ;
        String username = "root";
        String password = "password";
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(url, username, password );
        sql = con.createStatement();
        rs = sql.executeQuery("select * from userTable01");
        while(rs.next())
        {
%>
    
         <%=rs.getLong("user_id") %>
         <%=rs.getString("user_name") %>
         <%=rs.getString("user_password") %>
         <%=rs.getString("user_true_name") %>
         <%=rs.getInt("user_age") %>
         <%=rs.getString("user_sex") %>
        
<%=rs.getString("user_address") %>

         <%=rs.getString("user_telphone") %>
         <%=rs.getDate("add_time") %>
    
       
<%         }
    }catch(Exception e)
    {
        out.print("程序出现异常"+" "+e);
        //out.print(e);   
    }
%>

热门栏目