① 怎樣通過XML和java實現SQL和MYSQL的異構數據交換有代碼的做好,先謝謝啦!
SAXReader
reader
=
new
SAXReader();
Document
doc=reader.read(new
File("src/Cinema.xml"));
Element
eleRoot=doc.getRootElement();
for(Iterator
its=eleRoot.elementIterator();its.hasNext();){
Element
eleCount=(Element)its.next();
Iterator
it=eleCount.elementIterator();
while(it.hasNext()){
Element
eleName=(Element)it.next();
}
用這些代碼可以實現從XML中讀取數據
然後建立連接用一個實體類用來臨時存放SQL數據把
用List<News>存放
Class.forName("oracle.jdbc.OracleDriver");
String
url="jdbc:oracle:thin:@192.168.0.200:1521:tarena";
Connection
con=DriverManager.getConnection(url,"hsd1103","hsd1103");
String
str="insert
into
news
value(?,?,?,?,?)"//問號是對應下面你所要傳遞的值和
你SQL中的欄位值對應
News
news=new
News();
PreparedStatement
stmt=PreparedStatement
pstm
=
con.prepareStatement();
//把xml中的數據放置到sql中
stmt.setInt(1,news.getID())
stmt.setString(2,news.getName);
stmt.setString(3,news.getAcc());
.
.
.
按照這樣的方式些就可以了我用的是oracle