<%@ page contenttype="text/html; charset=gb2312" %>
<%@ page language="java"%>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<html>
<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type">
</head>
<body>
<%
int i=0;
string temp=null;
string parcode = request.getparameter("code");
string strsql;
try{
connection con;
statement stmt;
resultset rs;
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
string url="jdbc:oracle:thin:@192.168.15.248:1521:ycdb";
con=drivermanager.getconnection(url,"webcfcquery","kill859");
//out.println("<center>jdbc串連oracle資料庫</center><br><br>");
stmt=con.createstatement();
strsql = "select account_holder,description from account_holder ";
if(parcode!=null)
strsql += " where account_holder="+ parcode +"";
rs=stmt.executequery(strsql);
fileoutputstream fo=new fileoutputstream("/usr/local/tomcat/webapps/vehicles/treasurer_voucher.xml");
printstream so = new printstream(fo);
while(rs.next()){
string col1=rs.getstring(1);
string col2=rs.getstring(2);
try{
if(i==0){
so.println("<?xml version=/"1.0/" encoding=/"gb2312/" ?>");
so.println("<ufinterface roottag=/"voucher/" billtype=/"gl/" subtype=/"/" replace=/"y/" receiver=/"1051/" sender=/"1101/" isexchange=/"y/" filename=/"會計憑證.xml/">");
so.println("<voucher id=/"1234560102/">");
// 注意:這種寫法在xml檔案顯示時會報錯,不知道為什嗎? so.println("<custcode>"+col1+"</custcode>");
so.print("<custcode>");
if(col2==null) { //如果不判斷對象col2是否為null值,那麼在進行編碼轉換時可能會出現nullpointerexception異常
so.print(col2);
} else { //因為前面已經定義xml檔案的編碼顯示方式是gb2312,所以在將字串col2寫入xml之前需轉換成gb2312,這樣在xml檔案中漢字才能正常顯示。
byte[] temp_col = col2.getbytes("gb2312");
col2 = new string(temp_col);
so.print(col2);
}
so.println("</custcode>");
}
}catch(exception e){
out.println(e.tostring());
}
i++;
}
so.println("</voucher>");
so.println("</ufinterface>");
so.close();
}catch(exception e){
out.println(e);
}
%>
</body>
</html>
文章整理:站長天空 網址:http://www.z6688.com/