Home > Database > Mysql Tutorial > 获取mysql内容,生成xml文件,并且以webservice形式发送_MySQL

获取mysql内容,生成xml文件,并且以webservice形式发送_MySQL

WBOY
Release: 2016-06-01 13:14:46
Original
875 people have browsed it
<xyt><news id><url></url><title></title></news></xyt>
Copy after login
Copy after login
其实是三个知识点综合到一起的,包括如何访问mysql,如何生成xml文件,如何使用进行webservice开发

好了,话不多说,直接粘代码

package com.service;import java.io.FileOutputStream;import java.io.IOException;import java.sql.*;import org.jdom.*;import org.jdom.output.XMLOutputter;public class NewsImpl implements NewsInterface{		public String GetNews(int StartPage, int EndPage) 	{		// 创建根节点 list;	Element root = new Element("xyt");		 // 根节点添加到文档中;	Document Doc = new Document(root);	 	Connection conn = null;	Statement stmt = null ;	 // 此处 for 循环可替换成 遍历 数据库表的结果集操作;	try {			Class.forName("org.gjt.mm.mysql.Driver").newInstance();			 String url_connect ="jdbc:mysql://localhost/nxu_life?user=root&password=12345&useUnicode=true&characterEncoding=gb2312";		//first为你的数据库名			 	try {					conn = DriverManager.getConnection(url_connect);				} catch (SQLException e0) {					// TODO Auto-generated catch block					e0.printStackTrace();				}						try {					stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);				} catch (SQLException e00) {					// TODO Auto-generated catch block					e00.printStackTrace();				}		String sql="select page_id,title,url,publishtime,page,department from news where page_id>="+StartPage+" and page_id
    
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template