JSP exports data from the database tutorial and outputs the generated XML file
/*
Database structure
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 ', ' n ', ' M ', ' sdfg ', ' 321321 ', now ());
XML Document Structure
<?xml version= "1.0" encoding= "gb2312"?>
-<users>
-<user>
<id>1</id>
<name>wgy</name>
<password>123123</password>
<true_name>www.111cn.net</true_name>
<age>23</age>
<sex>M</sex>
<address>sdfg</address>
<telphone>321321</telphone>
<add_time>2010-01-06</add_time>
</user>
</users>
*/
<%@ page ContentType = "Text/xml;charset =gb2312"%>
<%@ page import = "java.sql.*"%>
<?xml Version = "1.0" encoding = "gb2312"?>
<users>
<%
Connection con = null;
Statement sql = null;
ResultSet rs = null;
Try
{
String url = "Jdbc:mysql tutorial://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 ())
{
%>
<user>
<id><%=rs.getlong ("user_id")%></id>
<name><%=rs.getstring ("user_name")%></name>
<password><%=rs.getstring ("User_password")%></password>
<true_name><%=rs.getstring ("User_true_name")%></true_name>
<age><%=rs.getint ("User_age")%></age>
<sex><%=rs.getstring ("User_sex")%></sex>
<address><%=rs.getstring ("user_address")%></address>
<telphone><%=rs.getstring ("User_telphone")%></telphone>
<add_time><%=rs.getdate ("Add_time")%></add_time>
</user>
<%}
}catch (Exception e)
{
Out.print ("program appears abnormal" + "" +e);
Out.print (e);
}
%>
</users>