【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“ysfManage.java”一文,供大家参考学习
package flashRemoting.ysf;
import java.sql.*;
import java.io.*;
import java.io.Serializable;
import java.io.StringReader;
import org.xml.sax.InputSource;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
import sun.jdbc.rowset.*;
import org.w3c.dom.*;
import javax.
xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
public class ysfManage {
private String resultPacket;
private Node nd;
private Node childNd;
private Node grandson;
private Node grandsonchildNd;
private NodeList childNlst;
private NamedNodeMap nnm;
private NamedNodeMap childNnm;
private String sqlStmt = null;
private String whereClause = null;
private String updateFlds = null;
private String fldList = null;
private String valList = null;
private String keyName;
private String keyValue;
public String saveSQLData(String userName, String userPass,
String datasource, String deltaData) throws
Exception {
//鑾峰緱涓涓猉ML鏂囦欢鐨勮В鏋愬櫒
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//涓鸿В鏋怷ML瀛楃涓茬敓鎴怐OM鏂囨。鐨勬帴鍙g被锛屼互渚胯闂瓺OM銆?
DocumentBuilder builder = factory.newDocumentBuilder();
//鏍规嵁瀛楃涓插垱寤轰竴涓猄tringReader瀹炰緥
StringReader XMLReader = new StringReader(deltaData);
//鏍规嵁StringReader瀹炰緥鍒涘缓涓涓狪nputSource瀹炰緥
InputSource XMLInputSource = new InputSource(XMLReader);
//瑙f瀽XML瀛楃涓?
Document Doc = builder.parse(XMLInputSource);
//鑾峰緱Root鍏冪礌
Element rt = Doc.getDocumentElement();
//鑾峰緱update_packet鑺傜偣涓殑灞炴т俊鎭?
String tableName = rt.getAttribute("tableName");
String transID = rt.getAttribute("transID");
String nullValue = rt.getAttribute("nullValue");
resultPacket = "<results_packet transID=\"" + transID + "\" >";
//鑾峰緱Root鍏冪礌鐨勫瓙鑺傜偣鍒楄〃
String sqlStatement = "";
Connection connection = null;
PreparedStatement stmt = null;
boolean rs;
boolean logined = ysfLogin.login(userName, userPass);
System.out.println(logined);
if (logined) {
System.out.println("寤虹珛杩炴帴锛屽紑濮嬫墽琛屾暟鎹簱鎿嶄綔");
try {
Context ctx = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup(datasource);
connection = ds.getConnection();
NodeList nlst = rt.getChildNodes();
//閬嶅巻鑺傜偣鏍?
for (int i = 0; i < nlst.getLength(); i++) {
//鑾峰彇update_packet鑺傜偣鐨勫瓙鑺傜偣
nd = nlst.item(i);
//鑾峰彇update_packet鑺傜偣瀛愯妭鐐癸紙delete銆乽pdate鎴杋nsert锛夌殑灞炴ф槧灏?
nnm = nd.getAttributes();
//鑾峰彇瀛愯妭鐐癸紙delete銆乽pdate鎴杋nsert锛夌殑灞炴d鐨勫?
//鍥犱负nnm.getLength()==1,鎵浠ユ棤椤讳娇鐢ㄥ惊鐜?
childNd = nnm.item(0);
childNlst = nd.getChildNodes();
//鏍规嵁涓嶅悓鑺傜偣鍒涘缓涓嶅悓鐨凷QL璇彞
if (nd.getNodeName().equalsIgnoreCase("delete")) {
System.out.println("delete");
for (int j = 0; j < childNlst.getLength(); j++) {
grandson = childNlst.item(j);
childNnm = grandson.getAttributes();
//鍥犱负delete鑺傜偣涓嬩粎鏈変竴涓瓙鑺傜偣锛?
//鎵浠ワ紝鏃犻渶楠岃瘉key灞炴у氨鍙互鍒涘缓whereClause瀛愬彞
whereClause = "WHERE " +
childNnm.getNamedItem("name").getNodeValue() +
" = " +
childNnm.getNamedItem("oldValue").getNodeValue();
}
sqlStmt = "DELETE FROM " + tableName + " " + whereClause;
System.out.println(sqlStmt);
}
else if (nd.getNodeName().equalsIgnoreCase("update")) {
System.out.println("update");
for (int j = 0; j < childNlst.getLength(); j++) {
grandson = childNlst.item(j);
System.out.println(j);
childNnm = grandson.getAttributes();
//楠岃瘉key灞炴