View Code
1 <%@ page contentType="text/html; charset=gb2312" %>
2 <%@ page language="java"%>
3 <%@ page info="database handler"%>
4 <%@ page import="java.io.*"%>
5 <%@ page import="java.lang.*"%>
6 <%@ page import="java.util.*"%>
7 <%@ page import="java.sql.*"%>
8 <%@ page import="javax.servlet.*"%>
9 <%@ page import="javax.servlet.http.*"%>
10 <html>
11 <head>
12 <meta content="text/html; charset=gb2312" http-equiv="content-type">
13 </head>
14 <body>
15 <%
16 int i=0;
17 String temp=null;
18 String parCode = request.getParameter("code");
19 String strSql;
20 try{
21 Connection con;
22 Statement stmt;
23 ResultSet rs;
24 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
25 String url="jdbc:oracle:thin:@192.168.15.248:1521:ycdb";
26 con=DriverManager.getConnection(url,"webcfcquery","kill859");
27 //out.println("<center>jdbc连接Oracle数据库</center><br><br>");
28 stmt=con.createStatement();
29 strSql = "select account_holder,description from account_holder ";
30 if(parCode!=null)
31 strSql += " where account_holder='"+ parCode +"'";
32 rs=stmt.executeQuery(strSql);
33 FileOutputStream fo=new FileOutputStream("/usr/local/tomcat/webapps/vehicles/treasurer_voucher.xml");
34 PrintStream so = new PrintStream(fo);
35 while(rs.next()){
36 String col1=rs.getString(1);
37 String col2=rs.getString(2);
38 try{
39 if(i==0){
40 so.println("<?xml version=\"1.0\" encoding=\"gb2312\" ?>");
41 so.println("<ufinterface roottag=\"voucher\" billtype=\"gl\" subtype=\"\" replace=\"Y\" receiver=\"1051\" sender=\"1101\" isexchange=\"Y\" filename=\"会计凭证.xml\">");
42 so.println("<voucher id=\"1234560102\">");
43
44
45 // 注意:这种写法在xml文件显示时会报错,不知道为什么? so.println("<custcode>"+col1+"</custcode>");
46 so.print("<custcode>");
47 if(col2==null) { //如果不判断对象col2是否为null值,那么在进行编码转换时可能会出现NullPointerException异常
48 so.print(col2);
49 } else { //因为前面已经定义xml文件的编码显示方式是gb2312,所以在将字符串col2写入xml之前需转换成gb2312,这样在xml文件中汉字才能正常显示。
50 byte[] temp_col = col2.getBytes("gb2312");
51 col2 = new String(temp_col);
52 so.print(col2);
53 }
54 so.println("</custcode>");
55
56 }
57 }catch(Exception e){
58 out.println(e.toString());
59 }
60 i++;
61 }
62 so.println("</voucher>");
63 so.println("</ufinterface>");
64 so.close();
65 }catch(Exception e){
66 out.println(e);
67 }
68 %>
69 </body>
70 </html>