JSP exports data from the database and outputs the generated XML file

Source: Internet
Author: User
Tags mysql tutorial

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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.