Java语言,在cxf+spring搭建的webservice链接数据库查询的数据拼接成XML返回
publicUserqueryById(intuserid)throwsException{Useruser=null;Stringsql="SELECT*FROMtex...
public User queryById(int userid) throws Exception{
User user = null;
String sql="SELECT * FROM text WHERE userid = ?";
PreparedStatement pstmt = null;
DataBaseConnection dbc = null;
try{
dbc= new DataBaseConnection();
pstmt=dbc.getConnection().prepareStatement(sql);
pstmt.setInt(1,userid);
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
user=new User();
user.setUserid(rs.getInt(1));
user.setUsername(rs.getString(2));
user.setEmail(rs.getString(3));
user.setTel(rs.getString(4));
user.setIswork(rs.getInt(5));
user.setDepartment(rs.getString(6));
user.setTeam(rs.getInt(7));
user.setPosition(rs.getString(8));
user.setDutysupervisor(rs.getString(9));
}
rs.close();
pstmt.close();
}catch(Exception e){
throw new Exception(e);
}
finally{
dbc.close();
}
return user;
}
public String reurnXML(int userid) {
StringBuilder xml = new StringBuilder();
try {
User user = queryById(userid);
xml.append("<ITIL>");
xml.append("<INFO>");
xml.append("<PUSH_SRC>SMS</PUSH_SRC>");
xml.append("</INFO>");
xml.append("<DATAS>");
xml.append(user.toXML());
xml.append("</DATAS>");
xml.append("</ITIL>");
} catch (Exception e) {
e.printStackTrace();
}
return xml.toString();
}
因为百度限制,所以代码不能全发上来 展开
User user = null;
String sql="SELECT * FROM text WHERE userid = ?";
PreparedStatement pstmt = null;
DataBaseConnection dbc = null;
try{
dbc= new DataBaseConnection();
pstmt=dbc.getConnection().prepareStatement(sql);
pstmt.setInt(1,userid);
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
user=new User();
user.setUserid(rs.getInt(1));
user.setUsername(rs.getString(2));
user.setEmail(rs.getString(3));
user.setTel(rs.getString(4));
user.setIswork(rs.getInt(5));
user.setDepartment(rs.getString(6));
user.setTeam(rs.getInt(7));
user.setPosition(rs.getString(8));
user.setDutysupervisor(rs.getString(9));
}
rs.close();
pstmt.close();
}catch(Exception e){
throw new Exception(e);
}
finally{
dbc.close();
}
return user;
}
public String reurnXML(int userid) {
StringBuilder xml = new StringBuilder();
try {
User user = queryById(userid);
xml.append("<ITIL>");
xml.append("<INFO>");
xml.append("<PUSH_SRC>SMS</PUSH_SRC>");
xml.append("</INFO>");
xml.append("<DATAS>");
xml.append(user.toXML());
xml.append("</DATAS>");
xml.append("</ITIL>");
} catch (Exception e) {
e.printStackTrace();
}
return xml.toString();
}
因为百度限制,所以代码不能全发上来 展开
2个回答
2015-05-09
展开全部
将cxf与spring相关的架包拷到lib目录下。
然后在classpath下新建一个cxfbeans.xml(进行cxf与spring的集成)文件和applicationContext.xml(进行ssh2的配置)。
然后在classpath下新建一个cxfbeans.xml(进行cxf与spring的集成)文件和applicationContext.xml(进行ssh2的配置)。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询