WebPrint.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:48k
源码类别:
OA系统
开发平台:
Java
- /**
- 公司:北京方成科技发展有限公司
- 作者:梅勇
- 日期:2001.08.24
- */
- import java.io.*;
- import java.text.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.sql.*;
- //import explato.database.*;
- import sun.io.ByteToCharConverter;
- import org.xml.sax.* ;
- import org.apache.xerces.dom.TextImpl;
- import org.w3c.dom.Attr;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- //import dom.DOMParserWrapper;
- //import dom.wrappers.DOMParser;
- //websphere+db2
- //import COM.ibm.db2.jdbc.app.*;
- public class WebPrint extends HttpServlet {
- private int iPosition=1; //用于fc_select类查询中传位置参数
- //数据源名称,用户名,密码.用于报表查询时连接另外的数据源使用,用于fc_select1,fc_select2
- private String strDataSource="";
- private String strUserName="";
- private String strPassword="";
- private String strXml="";
- private ResultSet rs = null;
- private ResultSet rs1 = null;
- private ResultSet rs2 = null;
- private Connection con = null;
- //private ConnectionManager cm=null;
- private Document document=null;
- public void doPost(HttpServletRequest req,
- HttpServletResponse res)
- throws IOException, ServletException
- {
- //设置演示版,
- /*
- long Time1=1026000000+23328000;
- long curTime=0;
- curTime=System.currentTimeMillis();
- curTime=curTime/1000;
- //每天的时间为 86400
- if(curTime>Time1){
- System.out.println("演示版已到期,系统将不正常!");
- return ;
- }
- //------------------
- */
- res.setContentType("text/html;charset=UTF-8");
- PrintWriter out = res.getWriter();
- try {
- /*
- 采用odbc+jdbc做连接的方法:
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:ereport";
- Class.forName(sDBDriver);
- con = DriverManager.getConnection(sConnStr,"sa","");
- 采用tomcat 用自做的连接池建立连接的方法:
- ServletContext application = getServletContext();
- cm=(ConnectionManager)application.getAttribute ( "fcConPoolManager" );
- //demo是配置文件中逻辑数据库的名字,同时也是连接池的名字
- con = cm.getConnection( "demo" ); //或者 con = cm.getConnection( "demo", 30000 ); //30000是不能马上取到连接时的等待时间(以毫秒计)
- websphere+db2:
- Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
- con=DriverManager.getConnection("jdbc:db2:sample","meiyong","");
- */
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:webgrid";
- Class.forName(sDBDriver);
- con = DriverManager.getConnection(sConnStr,"sa","");
- } catch (Exception e){
- //out.println("读表发生错误");
- }
- finally {
- //if( con != null ){
- // cm.freeConnection( "demo", con );
- //}
- }
- //-------------------------------------------------------
- //strKey为?后的值
- String strKey=new String(req.getQueryString());
- //计算前台SEND来的XML串 存入strXml中
- BufferedReader in = req.getReader();
- String line = null;
- strXml="";
- while ((line = in.readLine()) != null) {
- strXml=strXml+line;
- }
- //parse XML串
- try {
- //DOMParserWrapper parser =
- //(DOMParserWrapper)Class.forName("dom.wrappers.DOMParser").newInstance();
- //document = parser.parseXml(strXml);
- org.apache.xerces.parsers.DOMParser parser =
- new org.apache.xerces.parsers.DOMParser();
- InputSource myStr=new InputSource();
- Reader myStr1=new StringReader(strXml);
- myStr.setCharacterStream(myStr1);
- parser.parse(myStr);
- document = parser.getDocument();
- }
- catch (Exception e) {
- }
- //--------------------------------------------------------
- //用一个CASE语句来处理各种方法
- if (strKey.equals("fillcombox")) out.print(fillcombox());
- //用于用SQL语句填充combox
- if (strKey.equals("checksql")) out.print(checksql());
- //用于检查SQL语句是否合法
- /*
- 当数据库为oracle时应加上此四行
- if (strKey.equals("fc_insertClob")) out.print(fc_insertClob());
- if (strKey.equals("fc_updateClob")) out.print(fc_updateClob());
- if (strKey.equals("fc_loadClob")) out.print(fc_loadClob());
- if (strKey.equals("fc_loadClob1")) out.print(fc_loadClob1());
- */
- if (strKey.equals("GetReportCell")) out.print(GetReportCell()); //跨表取数
- if (strKey.equals("fc_insert")) out.print(fc_insert());
- if (strKey.equals("fc_insert1")) out.print(fc_insert1()); //新增主子表
- if (strKey.equals("fc_update1")) out.print(fc_update1()); //新增主子表
- if (strKey.equals("fc_select")) out.print(fc_select());
- if (strKey.equals("fc_FieldToTable")) out.print(fc_FieldToTable());
- if (strKey.equals("GetDB")) out.print(GetDB());
- if (strKey.equals("fc_select1")) out.print(fc_select1()); //多个SQL同时查的查询
- if (strKey.equals("fc_select2")) out.print(fc_select2()); //明细和汇总都要的查询
- if (strKey.equals("twors")) out.print(twors());//两个结果集的测试
- if (strKey.equals("sqltoxml")) out.print(sqltoxml());//两个结果集的测试
- if (strKey.equals("dsnSetSession"))
- {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strValue="";
- try {
- //当此节点值为空时
- strValue=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- }
- catch (Exception e) { }
- HttpSession session = req.getSession(true);
- session.setAttribute(strName, strValue);
- out.print("");
- }
- if (strKey.equals("dsnGetSession"))
- {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- HttpSession session = req.getSession(true);
- String strSR=session.getAttribute(strName).toString();;
- out.print(strSR);
- }
- if (strKey.equals("loadprint")) {
- String strX="function%20detachPage%28%29%7B%20htmlToptmp%3DhtmlTop%3B%20htmlBottomtmp%3DhtmlBottom%3B%20var%20iStart%3D0%3B%20var%20iEnd%3D0%3B%20var%20lngEndLine%3Dt.rows.length-tabCauda%3B%20var%20colwidthXML%3DLoadUserData%28%22setcolwidth%22%2C%22ReportColWidth%22+ReportName%29%3B%20effectiveWidth%3DparseInt%28repWidth-tabLeft-tabRight%29%3B%20var%20oXML1%3Dnew%20ActiveXObject%28%22Microsoft.XMLDOM%22%29%3B%20oXML1.async%3D%22false%22%3B%20oXML1.loadXML%28%22%3Croot%3E%22%20+colwidthXML+%22%3C/root%3E%22%29%3B%20sumcol%3D0%3B%20var%20compressRate%3D1%3B%20if%28prnSet.compressWidth%3D%3D1%29%20%7B%20for%20%28var%20j%3D0%3Bj%3CMaxCols%3Bj++%29%7B%20if%20%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colSelect%22%29%3D%3D%22block%22%29%7B%20sumcol%3Dsumcol+parseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29%3B%20%7D%20%7D%20compressRate%3DeffectiveWidth/%28sumcol+MaxCols%29%3B%20if%28compressRate%3E%3D1%20%29%20%7B%20compressRate%3D1%3B%20%7D%20compressColWidth%28compressRate%29%3B%20%7D%20var%20hcompressRate%3D1%3B%20var%20t_outerHTMLbak%3Dt.outerHTML%3B%20if%28prnSet.compressHeight%3D%3D1%29%20%7B%20cur1%3D0%3B%20for%20%28var%20i%3DtabHead%3Bi%3ClngEndLine%3Bi++%29%20%7B%20cur1%3Dcur1+parseInt%28t.rows%28i%29.style.height%29%3B%20%7D%20hcompressRate%3D%28repHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29/%28cur1+lngEndLine-tabHead%29%20%3B%20if%28hcompressRate%3E%3D1%20%29%20%7B%20hcompressRate%3D1%3B%20%7D%20compressRowHeight%28hcompressRate%2CtabHead%2ClngEndLine%29%3B%20%7D%20if%20%28prnSet.compressFont%21%3D1%29%20%7B%20var%20compressFont%3D0%3B%20if%28hcompressRate%3CcompressRate%29%20%7B%20compressFont%3DhcompressRate%3B%20%7D%20else%20%7B%20compressFont%3DcompressRate%3B%20%7D%20if%28compressFont%3C1%29%7B%20t.style.fontSize%3DparseFloat%28t.style.fontSize%29*compressFont%3B%20%7D%20%7D%20setAutoturnRow%28%29%3B%20cur1%3D0%3B%20for%20%28var%20i%3DtabHead%3Bi%3ClngEndLine%3Bi++%29%20%7B%20cur1%3Dcur1+parseInt%28t.rows%28i%29.style.height%29%3B%20if%20%28cur1%3E%3DrepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%7C%7C%20i%3D%3DlngEndLine-1%29%7B%20if%20%28cur1%3D%3DrepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%20%7B%20cur1%3D0%3B%20%7D%20else%20%7B%20cur1%3DparseInt%28t.rows%28i%29.style.height%29%3B%20%7D%20sumcol%3D0%3B%20var%20bFind%3Dfalse%3B%20iStart%3D0%3B%20iEnd%3D0%3B%20if%20%28i%3D%3DlngEndLine-1%29%7B%20perPageHTML%3DperPageHTML+t.rows%28i%29.outerHTML%20%3B%20%7D%20for%20%28var%20j%3D0%3Bj%3CMaxCols%3Bj++%29%7B%20if%20%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colSelect%22%29%3D%3D%22block%22%29%7B%20sumcol%3Dsumcol+parseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29*compressRate%3B%20%7D%20if%20%28sumcol%3E%3DeffectiveWidth%20%7C%7C%20j%3D%3DMaxCols-1%29%7B%20if%20%28sumcol%3C%3DeffectiveWidth%29%7B%20iEnd%3Dj%3B%20sumcol%3D0%3B%20%7D%20else%20%7B%20iEnd%3Dj-1%3B%20sumcol%3DparseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29*compressRate%3B%20%7D%20var%20s1%3DHideCol%28strCol%2CiStart%2CiEnd%29%3B%20bFind%3Dtrue%3B%20PageDataAdd%28Pages%29%3B%20arrPage%5BPages%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+PageHeadHTML%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+perPageHTML+PageCaudaHTML+%22%3C/Table%3E%22%20+%22%3Cimg%20%3E%22%3B%20if%20%28i%3D%3DlngEndLine-1%29%7B%20if%28cur1%3ErepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%7B%20PageDataAdd%28Pages+1%29%3B%20arrPage%5BPages+1%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages+1%5D%3DarrPage%5BPages+1%5D+PageHeadHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20%7D%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20if%20%28%28j%3D%3DMaxCols-1%20%29%20%26%26%20%28iEnd%3D%3Dj-1%29%20%29%7B%20var%20s1%3DHideCol%28strCol%2CMaxCols-1%2CMaxCols-1%29%3B%20bFind%3Dtrue%3B%20PageDataAdd%28Pages%29%3B%20arrPage%5BPages%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+PageHeadHTML%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+perPageHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20if%20%28i%3D%3DlngEndLine-1%29%7B%20if%28cur1%3ErepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%7B%20PageDataAdd%28Pages+1%29%3B%20arrPage%5BPages+1%5D%3DhtmlTop+htmlBottom+tabstyle+s1%20%3B%20arrPage%5BPages+1%5D%3DarrPage%5BPages+1%5D+PageHeadHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20%7D%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20iStart%3DiEnd+1%3B%20%7D%20%7D%20perPageHTML%3D%22%22%3B%20%7D%20perPageHTML%3DperPageHTML+t.rows%28i%29.outerHTML%20%3B%20%7D%20mdblRate%3D1%3B%20htmlTop%3D%22%22%3B%20htmlBottom%3D%22%22%3B%20t.outerHTML%3Dt_outerHTMLbak%3B%20t.style.display%3D%22none%22%3B%20for%28var%20i%3D0%3Bi%3CPages%3Bi++%29%7B%20arrPage%5Bi%5D%3Dfc_RepStr%28arrPage%5Bi%5D%2C%22%28P%29%22%2CPages+%22%22%29%3B%20%7D%20%7D%20";
- out.println(strX);
- }
- }
- /*
- //下面是自定义的方法
- //--------------------------------------
- private String fc_insertClob() {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String strTable1=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- String sTmp = "";
- //System.out.println("1:"+strTable) ;
- //java.sql.Blob myBlob = null;
- java.sql.Clob myClob = null;
- java.sql.Clob myClob1 = null;
- // set Oracle's Auto Commit feature to false.
- // This is necessary when manipulating Blobs and Clobs.
- // CallableStatement cstmt=null;
- try {
- con.setAutoCommit(false);
- Statement stmt = con.createStatement();
- stmt.execute("insert into fccell values ('"+strName+"',EMPTY_CLOB(),EMPTY_CLOB(),null)");
- // ============== Manipulating the Clob column ======================
- // get a reference to the clob column
- stmt.execute("select * from fccell where fstrtablename='"+strName+"'");
- ResultSet crs = stmt.getResultSet();
- while ( crs.next() ) {
- myClob = crs.getClob("fstrtable");
- //oracle用此行
- java.io.OutputStream osss =((weblogic.jdbc.common.OracleClob) myClob).getAsciiOutputStream();
- //java.io.OutputStream osss = myClob.getAsciiOutputStream();
- byte[] bss = strTable.getBytes("ASCII");
- osss.write(bss);
- osss.flush();
- myClob1 = crs.getClob("fstrtable1");
- java.io.OutputStream osss1 =((weblogic.jdbc.common.OracleClob) myClob1).getAsciiOutputStream();
- //java.io.OutputStream osss1 = myClob1.getAsciiOutputStream();
- byte[] bss1 = strTable1.getBytes("ASCII");
- osss1.write(bss);
- osss1.flush();
- }
- con.commit();
- // read back the clob
- //System.out.println("nReading the clob back from the table and displaying:");
- }
- catch (Exception e){
- e.printStackTrace();
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_updateClob() {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String strTable1=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- String sTmp = "";
- //System.out.println("1:"+strSql) ;
- //java.sql.Blob myBlob = null;
- java.sql.Clob myClob = null;
- java.sql.Clob myClob1 = null;
- // set Oracle's Auto Commit feature to false.
- // This is necessary when manipulating Blobs and Clobs.
- // CallableStatement cstmt=null;
- try {
- //con.setAutoCommit(false);
- Statement stmt = con.createStatement();
- //System.out.println("删除成功!"+strName);
- stmt.executeUpdate("delete from fccell where fstrTableName='"+strName+"'");
- //con.commit();
- //if (1==1){
- // stmt.close();
- // return "";
- //}
- con.setAutoCommit(false);
- stmt = con.createStatement();
- //stmt.executeUpdate("delete from fccell where fstrTableName='"+strName+"'");
- //System.out.println("删除成功!");
- stmt.execute("insert into fccell values ('"+strName+"',EMPTY_CLOB(),EMPTY_CLOB(),null)");
- //stmt.execute("update fccell set fstrtablename='"+strName+"',fstrtable=EMPTY_CLOB(),fstrtable1=EMPTY_CLOB() where fstrtableName='"+strName+"'");
- // ============== Manipulating the Clob column ======================
- // get a reference to the clob column
- stmt.execute("select * from fccell where fstrtablename='"+strName+"'");
- ResultSet crs = stmt.getResultSet();
- while ( crs.next() ) {
- myClob = crs.getClob("fstrtable");
- //oracle时用此行
- java.io.OutputStream osss =((weblogic.jdbc.common.OracleClob) myClob).getAsciiOutputStream();
- //java.io.OutputStream osss = myClob.getAsciiOutputStream();
- byte[] bss = strTable.getBytes("ASCII");
- osss.write(bss);
- osss.flush();
- myClob1 = crs.getClob("fstrtable1");
- java.io.OutputStream osss1 =((weblogic.jdbc.common.OracleClob) myClob1).getAsciiOutputStream();
- //java.io.OutputStream osss1 = myClob1.getAsciiOutputStream();
- byte[] bss1 = strTable1.getBytes("ASCII");
- osss1.write(bss1);
- osss1.flush();
- }
- con.commit();
- // read back the clob
- //System.out.println("nReading the clob back from the table and displaying:");
- }
- catch (Exception e){
- e.printStackTrace();
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_loadClob() {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String sTmp = "";
- //System.out.println("1:"+strSql) ;
- //java.sql.Blob myBlob = null;
- java.sql.Clob myClob = null;
- java.sql.Clob myClob1 = null;
- // set Oracle's Auto Commit feature to false.
- // This is necessary when manipulating Blobs and Clobs.
- // CallableStatement cstmt=null;
- try {
- Statement readclob = con.createStatement();
- readclob.execute("select * from fccell where fstrtablename='"+strName+"'");
- ResultSet rsreadclob = readclob.getResultSet();
- // read the clob in as and ASCII stream, write to a character array, and display
- String sTest="";
- while ( rsreadclob.next() ) {
- Clob myReadClob =rsreadclob.getClob("fstrtable");
- int iLen=1;
- iLen=(int)myReadClob.length();
- sTest=myReadClob.getSubString(1,iLen);
- //System.out.println("output " +sTest );
- sTmp=sTest;
- }
- }
- catch (Exception e){
- e.printStackTrace();
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_loadClob1() {
- //为了取另外一个备注字段值fstrTable1
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String sTmp = "";
- //System.out.println("1:"+strSql) ;
- //java.sql.Blob myBlob = null;
- java.sql.Clob myClob = null;
- java.sql.Clob myClob1 = null;
- // set Oracle's Auto Commit feature to false.
- // This is necessary when manipulating Blobs and Clobs.
- // CallableStatement cstmt=null;
- try {
- Statement readclob = con.createStatement();
- readclob.execute("select * from fccell where fstrtablename='"+strName+"'");
- ResultSet rsreadclob = readclob.getResultSet();
- // read the clob in as and ASCII stream, write to a character array, and display
- String sTest="";
- String sTest1="";
- while ( rsreadclob.next() ) {
- Clob myReadClob =rsreadclob.getClob("fstrtable1");
- int iLen=1;
- iLen=(int)myReadClob.length();
- sTest=myReadClob.getSubString(1,iLen);
- sTmp=sTest;
- //System.out.println("output " +sTest );
- }
- }
- catch (Exception e){
- e.printStackTrace();
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- */
- //--------------------------------------
- //两个结果集的示例,第一个用连接池打开,第二个用一般方式打开
- private String twors() {
- // Node root = document.getChildNodes().item(0);
- // String sField=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- // String sTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- /*
- String strSql="select flngVoucherID,fstrVoucherTypeName from Voucher" ;
- String sTmp="";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- while (rs.next()) {
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:ereport";
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,"sa","");
- String sT=rs.getString(1);
- Statement stmt1 = con1.createStatement();
- rs1 = stmt1.executeQuery("select fstrAccountName from voucherdetail Where flngVoucherId="+sT);
- while (rs1.next()) {
- System.out.println("科目:"+rs1.getString(1));
- }
- }
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp;
- */
- return "";
- }
- //--------------------------------------
- private String fc_FieldToTable() {
- Node root = document.getChildNodes().item(0);
- String sField=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String sTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String strSql="select "+sField+" From "+sTable ;
- String sTmp="";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp;
- }
- //--------------------------------------
- private String GetDB() {
- Node root = document.getChildNodes().item(0);
- String sConnect=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String sSql=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- sSql=fcTrans(sSql);
- //System.out.println(sSql);
- String sR="";
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; //建立数据库连接
- String sConnStr = "jdbc:odbc:"+sConnect ;
- try {
- Class.forName(sDBDriver);
- con = DriverManager.getConnection(sConnStr,"sa","");
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(sSql);//执行查询建立结果集
- if (rs.next()) {
- sR=rs.getString(1);
- }
- rs.close();
- stmt.close();
- }
- catch (Exception e){
- sR=e.getMessage();
- }
- return sR;
- }
- //--------------------------------------
- private String fc_select() {
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strPageNo=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iPageNo=Integer.parseInt(strPageNo,10);//页号
- String strPageSize=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- int iPageSize=Integer.parseInt(strPageSize,10);//页尺寸
- strSql=fcTrans(strSql);
- //System.out.println(strSql);
- String strX = "<root>";
- String sTmp = "";
- int iField=1;
- int iCount=1;
- int i=1;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- ResultSetMetaData rsmd=rs.getMetaData();
- while (rs.next()) {
- //每页30行
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strX = strX + "<record>";
- iCount=rsmd.getColumnCount();
- for (iField = 1 ; iField<=iCount ;iField++ )
- {
- //当有NULL字段名时,表示此则无需给值.用fcnull标记名区分.
- String colName=rsmd.getColumnName(iField);
- if (colName==null) {
- strX = strX + "<fcnull></fcnull>" ;
- }
- else {
- String sT=rs.getString(iField);
- if (sT==null) sT="";
- strX = strX + "<fc>" + sT +"</fc>" ;
- }
- }
- strX = strX + "</record>";
- }
- i = i + 1;
- }
- i=i-1;
- if (i>0) {
- strX = strX + "<pages>"+i+"</pages>";
- }
- strX = strX + "</root>";
- rs.close();
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- System.out.println(sTmp);
- e.printStackTrace();
- }
- return strX ;
- }
- //--------------------------------------
- private String fc_select1() {
- //将页号和页尺寸两个节点从第一个子节点和第二个子节点改为第一个子节点下的第一个子节点和第二个子节点
- //将第二个子节点空出来给设置数据源用.
- //第二个子节点下将有三个子节点:数据源名称,用户名,密码.
- Node root = document.getChildNodes().item(0);
- String strPageNo=root.getChildNodes().item(0).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- int iPageNo=Integer.parseInt(strPageNo,10);//页号
- String strPageSize=root.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iPageSize=Integer.parseInt(strPageSize,10);//页尺寸
- //数据源
- strDataSource=root.getChildNodes().item(1).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strUserName=root.getChildNodes().item(1).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- try {
- strPassword=root.getChildNodes().item(1).getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- }
- catch (Exception e){
- strPassword="";
- }
- //-------
- //多SQL查询
- String strX = "<root>";
- int ii=0;
- int i=1;
- //按顺序取出SQL节点
- for(ii=2;ii<root.getChildNodes().getLength();ii++){
- String strSql=root.getChildNodes().item(ii).getChildNodes().item(0).getNodeValue();
- strX=strX+fc_selectTmp(iPageNo,iPageSize,i,strSql);
- i=iPosition;
- } //For循环结束
- i=i-1;
- if (i>0) {
- strX = strX + "<pages>"+i+"</pages>";
- }
- strX = strX + "</root>";
- return strX ;
- }
- //--------------------------------------
- //计算一个SQL查询,供fc_select1 fc_select2类函数使用
- private String fc_selectTmp(int iPageNo,int iPageSize,int iPos,String strSql) {
- //iPageNo为起始页号,iPageSize为页尺寸,iPos为所有查询结果的行位置,strSql为要执行的SQL语句
- //返回SQL语句的运行结果,结果为以<record>...</record>形式的XML串
- //
- strSql=fcTrans(strSql);
- String sTmp = "";
- String strX = "";
- int iField=1;
- int iCount=1;
- int i=iPos;
- try {
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:"+strDataSource;
- Class.forName(sDBDriver);
- Connection conTmp = DriverManager.getConnection(sConnStr,strUserName,strPassword);
- /**
- 注:当改动数据库连接时应将下面这行的conTmp改为con,同时去掉上面四行.
- */
- Statement stmtTmp = conTmp.createStatement();
- ResultSet rsTmp = stmtTmp.executeQuery(strSql);
- ResultSetMetaData rsmdTmp=rsTmp.getMetaData();
- while (rsTmp.next()) {
- //每页30行
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strX = strX + "<record>";
- iCount=rsmdTmp.getColumnCount();
- for (iField = 1 ; iField<=iCount ;iField++ )
- {
- //当有NULL字段名时,表示此则无需给值.用fcnull标记名区分.
- String colName=rsmdTmp.getColumnName(iField);
- if (colName==null) {
- strX = strX + "<fcnull></fcnull>" ;
- }
- else {
- String sT=rsTmp.getString(iField);
- if (sT==null) sT="";
- strX = strX + "<fc>" + sT +"</fc>" ;
- }
- }
- strX = strX + "</record>";
- }
- i = i + 1;
- }
- rsTmp.close();
- stmtTmp.close();
- con.close();
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- System.out.println("0712:"+sTmp);
- System.out.println("0712:"+strSql);
- }
- iPosition=i; //用iPosition全局变量将i值传到调用函数中.
- //System.out.println("strX="+strSql);
- return strX;
- }
- //--------------------------------------
- //带分组小计的多SQL查询
- private String fc_select2() {
- //sXml的结构:
- //1页号 2页尺寸 3主SQL<1SQL语句 2<before... > > 4Group<1SQL语句 2GroupField >
- int i=1;
- String beforeSum="0"; //=0表示合计行在后,=1表示合计行在前。
- String strX = "";
- String strX1 = "";
- String strRetXml = ""; //返回的总的Xml串
- //将页号和页尺寸两个节点从第一个子节点和第二个子节点改为第一个子节点下的第一个子节点和第二个子节点
- //将第二个子节点空出来给设置数据源用.
- //第二个子节点下将有三个子节点:数据源名称,用户名,密码.
- Node root = document.getChildNodes().item(0);
- String strPageNo=root.getChildNodes().item(0).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- int iPageNo=Integer.parseInt(strPageNo,10);//页号
- String strPageSize=root.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iPageSize=Integer.parseInt(strPageSize,10);//页尺寸
- //数据源
- strDataSource=root.getChildNodes().item(1).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strUserName=root.getChildNodes().item(1).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- try {
- strPassword=root.getChildNodes().item(1).getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- }
- catch (Exception e){
- strPassword="";
- }
- //-------
- //第3个子节点的第1个子节点的值用如下求法.
- String strSql=root.getChildNodes().item(2).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- //strSql=fcTrans(strSql);
- //System.out.println(strSql);
- //第3个子节点的第2个子节点下的第1个子节点的值用如下求法.
- String strStartXml=""; //首合计行的xml串
- //总计行之类的
- try {
- //如有一个节点表示首合计行,如有二个节点表示第一为首合计行,第二为尾合计行
- String sStartSql=root.getChildNodes().item(2).getChildNodes().item(1).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- //此处现只假定只有一个查询,如有多个,则此处要用循环
- strStartXml=fc_selectTmp(iPageNo,iPageSize,i,sStartSql);
- i=iPosition;
- }
- catch (Exception e){
- }
- //-----------------
- String sGroup1="";
- String sGroup2="";
- //String sGroup3="";
- //第一个分组
- sGroup1=root.getChildNodes().item(3).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- sGroup1=fcTrans(sGroup1);
- //分组字段名
- String sGroupField1=root.getChildNodes().item(3).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- //第二个分组
- sGroup2=root.getChildNodes().item(4).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- sGroup2=fcTrans(sGroup2);
- String sGroupField2=root.getChildNodes().item(4).getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String sTmp = "";
- int iField=1;
- int iCount=1;
- String sGroupKey1=""; //保存分组字段的值
- String sGroupKey2="";
- String tmpsGroup="";
- try {
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:"+strDataSource;
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,strUserName,strPassword);
- Connection con2 = DriverManager.getConnection(sConnStr,strUserName,strPassword);
- /**
- 注:当改动数据库连接时应将下面的con1和con2改为con,同时去掉上面5行.
- */
- Statement stmt1 = con1.createStatement();
- Statement stmt2 = con2.createStatement();
- rs1 = stmt1.executeQuery(sGroup1);
- ResultSetMetaData rsmd1=rs1.getMetaData();
- while (rs1.next()) {
- //strX="";
- //strX1="";
- sGroupKey1=rs1.getString(1);
- //算出第一个分组的合计行值
- //if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strX = "<recordsum1>"; //设特别tagName用于在前台设底色等属性
- iCount=rsmd1.getColumnCount();
- //第一个字段是分组字段值,所以从2开始
- for (iField = 2 ; iField<=iCount ;iField++ )
- {
- //当有NULL字段名时,表示此则无需给值.用fcnull标记名区分.
- String colName=rsmd1.getColumnName(iField);
- if (colName==null) {
- strX = strX + "<fcnull></fcnull>" ;
- }
- else {
- String sT=rs1.getString(iField);
- if (sT==null) sT="";
- if(iField == 2)
- strX = strX + "<fc>小计 " + sT +"</fc>" ;
- else
- strX = strX + "<fc>" + sT +"</fc>" ;
- }
- }
- strX = strX + "</recordsum1>";
- //}
- if(sGroup2.equals("fcnull")){
- //只有一级分组
- //准备下一个的SQL语句
- tmpsGroup=fc_RepStr(strSql,"1999=1999","1999=1999"+" and " +sGroupField1+"='"+sGroupKey1+"'");
- //此处定合计行在明细行的前面还是后面
- if(beforeSum.equals("1")){
- //-------合计行在前
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX;
- }
- i++;
- strRetXml+=fc_selectTmp(iPageNo,iPageSize,i,tmpsGroup);
- i=iPosition;
- }
- else {
- //-------合计行在后
- strRetXml+=fc_selectTmp(iPageNo,iPageSize,i,tmpsGroup);
- i=iPosition;
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX;
- }
- i++;
- }
- }
- else { //有二级分组
- //准备下一个的SQL语句
- tmpsGroup=fc_RepStr(sGroup2,"1999=1999","1999=1999"+" and " +sGroupField1+"='"+sGroupKey1+"'");
- //System.out.println("my:"+tmpsGroup);
- rs2 = stmt2.executeQuery(tmpsGroup);
- ResultSetMetaData rsmd2=rs2.getMetaData();
- if(beforeSum.equals("1")){
- //-------合计行在前
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX;
- }
- i++;
- }
- while (rs2.next()) {
- sGroupKey2=rs2.getString(1);
- //算出第二个分组的合计行值
- strX1 = "<recordsum2>";
- iCount=rsmd2.getColumnCount();
- //第一个字段是分组字段值,所以从2开始
- for (iField = 2 ; iField<=iCount ;iField++ )
- {
- //当有NULL字段名时,表示此则无需给值.用fcnull标记名区分.
- String colName=rsmd2.getColumnName(iField);
- if (colName==null) {
- strX1 = strX1 + "<fcnull></fcnull>" ;
- }
- else {
- String sT=rs2.getString(iField);
- if (sT==null) sT="";
- if(iField == 2)
- strX1 = strX1 + "<fc>小 计 " + sT +"</fc>" ;
- else
- strX1 = strX1 + "<fc>" + sT +"</fc>" ;
- }
- }
- strX1 = strX1 + "</recordsum2>";
- //-------------------------------
- //准备下一个的SQL语句
- tmpsGroup=fc_RepStr(strSql,"1999=1999","1999=1999"+" and " +sGroupField1+"='"+sGroupKey1+"'"+" and " +sGroupField2+"='"+sGroupKey2+"'");
- //此处定合计行在明细行的前面还是后面
- if(beforeSum.equals("1")){
- //-------合计行在前
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX1;
- }
- i++;
- strRetXml+=fc_selectTmp(iPageNo,iPageSize,i,tmpsGroup);
- i=iPosition;
- }
- else {
- //-------合计行在后
- strRetXml+=fc_selectTmp(iPageNo,iPageSize,i,tmpsGroup);
- i=iPosition;
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX1;
- }
- i++;
- }
- }//二级分组的循环结束
- if(beforeSum.equals("0")){
- //-------合计行在后
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strRetXml+=strX;
- }
- i++;
- }
- } //判断有无二级分组的IF结束
- }//一级分组的循环结束
- //----- loop end
- //第3个子节点(mainsql)的第3个子节点下(end)的第1个子节点(sql)的值用如下求法.
- String strEndXml=""; //首合计行的xml串
- //总计行之类的
- try {
- //如有一个节点表示首合计行,如有二个节点表示第一为首合计行,第二为尾合计行
- String sStartSql=root.getChildNodes().item(2).getChildNodes().item(2).getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- //System.out.println("endsql:"+sStartSql);
- //此处现只假定只有一个查询,如有多个,则此处要用循环
- strEndXml=fc_selectTmp(iPageNo,iPageSize,i,sStartSql);
- i=iPosition;
- }
- catch (Exception e){
- }
- //-----------------
- i=i-1;
- if (i>0) {
- strRetXml = strStartXml+strRetXml +strEndXml+ "<pages>"+i+"</pages>";
- }
- strRetXml = "<root>"+strRetXml + "</root>";
- //rs.close();
- }
- catch (Exception e){
- e.printStackTrace() ;
- sTmp=e.getMessage() ;
- System.out.println("071201"+sTmp);
- }
- return strRetXml ;
- }
- //--------------------------------------
- private String fc_insert() {
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- String sTmp = "";
- // CallableStatement cstmt=null;
- try {
- Statement stmt = con.createStatement();
- // stmt.executeQuery(strSql);
- stmt.executeUpdate(strSql);
- /*
- cstmt=con.prepareCall("{call sp_getID(?)}");
- cstmt.registerOutParameter(1,java.sql.Types.INTEGER,1);
- cstmt.executeUpdate();
- sTmp="<dsnID>"+ cstmt.getInt(1)+"</dsnID>";
- */
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_insert1() {
- //凭证增加
- Node root = document.getChildNodes().item(0);
- String sTmp = "";
- CallableStatement cstmt=null;
- try {
- Statement stmt = con.createStatement();
- int i;
- //System.out.println(root.getChildNodes().getLength());
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- stmt.executeUpdate(strSql);
- String sID="1"; //存主表新生成的ID
- try {
- //SQL Server 的存储过程,用于计算自动ID
- cstmt=con.prepareCall("{call sp_getID(?)}");
- cstmt.registerOutParameter(1,java.sql.Types.INTEGER,1);
- cstmt.executeUpdate();
- sID=""+cstmt.getInt(1);
- }
- catch (Exception e1){
- try {
- //计算MS Access数据库的主表ID
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:webprint";
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,"sa","");
- Statement stmt1 = con1.createStatement();
- rs1 = stmt1.executeQuery("select max(flngSendOutID) From SendOut");
- if (rs1.next()) {
- sID=rs1.getString(1);
- }
- }
- catch (Exception e2){
- }
- }
- //追加子表内容
- for(i=1;i<root.getChildNodes().getLength();i++) {
- strSql=root.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- strSql=strSql+sID+" )";
- stmt.executeUpdate(strSql);
- }
- }
- catch (Exception e){
- System.out.println(e.getMessage()) ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_update1() {
- //凭证修改
- Node root = document.getChildNodes().item(0);
- String sTmp = "";
- String strSql="";
- try {
- Statement stmt = con.createStatement();
- int i;
- for(i=0;i<root.getChildNodes().getLength();i++) {
- strSql=root.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- stmt.executeUpdate(strSql);
- }
- }
- catch (Exception e){
- System.out.println(e.getMessage()) ;
- }
- return sTmp ;
- }
- //--------------------------------------
- /**
- *检查SQL语句是否为合法的SQL语句
- *@param sql 要检查的SQL语句.
- *@return 是则返回空,否则返回非空
- *@date 2002-05-20
- **/
- private String checksql() {
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- //System.out.println(strSql);
- String strX = "";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- rs.close();
- }
- catch (Exception e){
- strX=e.getMessage() ;
- }
- return strX ;
- }
- //--------------------------------------
- private String fillcombox() {
- //拼成的XML串的节点名为option,可以直接填入combox中
- //返回的XML串无根节点.
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- /*
- String strPageNo=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iPageNo=Integer.parseInt(strPageNo,10);//页号
- String strPageSize=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- int iPageSize=Integer.parseInt(strPageSize,10);//页尺寸
- */
- strSql=fcTrans(strSql);
- //System.out.println(strSql);
- String strX = "";
- String sTmp = "";
- int iField=1;
- int iCount=1;
- int i=1;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- ResultSetMetaData rsmd=rs.getMetaData();
- iCount=rsmd.getColumnCount();
- String sT="";
- while (rs.next()) {
- //每页30行
- //if ((i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) || iPageSize==-1) {
- //strX = strX + "<option>";
- if(iCount>1){
- //假定两列时,第一列为value,第二列为text
- sT=rs.getString(1);
- if (sT==null) sT="";
- strX+="<option value='" +sT;
- sT=rs.getString(2);
- if (sT==null) sT="";
- strX+="' >"+sT+"</option>";
- }else {
- //一列时则value和text相同
- sT=rs.getString(1);
- if (sT==null) sT="";
- strX+="<option value='" +sT;
- strX+="' >"+sT+"</option>";
- }
- // }
- i = i + 1;
- }
- //strX = strX + "</root>";
- rs.close();
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- System.out.println(sTmp);
- }
- return strX ;
- }
- //--------------------------------------
- private String SqlToField(String strSql) {
- //用一个SQL语句返回一个字段的第一个记录值
- String strR = "";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- if (rs.next()) {
- strR = rs.getString(1) ;
- }
- rs.close();
- stmt.close();
- }
- catch (Exception e){
- //out.println("读表发生错误");
- }
- return strR;
- }
- //--------------------------------------
- //报表增加
- //--------------------------------------
- private String GetReportCell() {
- //找到指定位置的单元的值.
- Node root = document.getChildNodes().item(0);
- String sRow = root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- int iRow=Integer.parseInt(sRow,10);
- String sCol =root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iCol=Integer.parseInt(sCol,10);
- String strTableName =root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- strTableName=fcTrans(strTableName);
- //int iRow=Integer.parseInt(sRow,10);
- String strSql="";
- //String strID=TableNameToID(strTableName);
- //strSql = "Select fstrDiv1 From cellsheet where flngID=" + strID + " and flngSheetNo=" + strPage ;
- strSql = "Select fstrTable1 From fcCell where fstrTableName='" + strTableName+"'" ;
- //String sLogCol=ToLogCol(sRow,sCol,"Select fstroCoor From cellsheet where flngID=" + strID + " and flngSheetNo=" + strPage );
- //int iCol=Integer.parseInt(sLogCol,10);
- String strR="";
- String strR1="";
- int iStart=0;
- int iStartTmp=0;
- int iTmp=0;
- int iEnd=0;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- if (rs.next()) {
- strR = rs.getString(1) ;
- }
- rs.close();
- stmt.close();
- //strR1=strR;
- //查找定位TR TD
- //iStart=strR.indexOf("%20id%3Dt%20",0);//查找 id=t
- for (int i=0;i<=iRow;i++) {
- iStartTmp=strR.indexOf("%3CTR",iStart+1);//TR开始符
- if (iStartTmp>0) {
- iStart=iStartTmp;
- }
- }
- if (iStartTmp>0) {
- for (int i=0;i<=iCol;i++) {
- iStartTmp=strR.indexOf("%3CTD",iStart+1); //TD开始符
- if (iStartTmp>0) {
- iStart=iStartTmp;
- }
- }
- iStart=strR.indexOf("%3E",iStart);//TD后的第一个>
- iEnd=strR.indexOf("%3C/TD%3E",iStart);//TD结束符
- if (iEnd>iStart && iStart>0) {
- strR=strR.substring(iStart+3,iEnd);
- }
- }
- }
- catch (Exception e){
- System.out.println(e.getMessage());
- }
- //return Integer.toString(iEnd) ;
- System.out.println(strR);
- return "<root>"+strR+"</root>";
- }
- //--------------------------------------
- //--------------------------------------
- //通用函数
- private String fc_RepStr(String mainStr,String findStr,String replaceStr){
- //多次替代
- int iStart=0;
- int iEnd=0;
- String sRet="";
- while (iStart<mainStr.length()) {
- iEnd=mainStr.indexOf(findStr,iStart);
- if (iEnd<0) {
- iEnd=mainStr.length();
- sRet=sRet+mainStr.substring(iStart,iEnd);
- }
- else {
- sRet=sRet+mainStr.substring(iStart,iEnd)+replaceStr;
- }
- iStart=iEnd+findStr.length();
- }
- return sRet;
- }
- private String rTrim(String str){
- String rstr = str;
- if(str == null)
- {
- rstr = "";
- }
- else
- {
- if(str.length() == 0) rstr = "";
- if(str.length() > 0)
- {
- for(int i = str.length() ; i > 0 ; i--)
- {
- if(str.substring(i-1,i).equals(" "))
- rstr = rstr.substring(0,i-1);
- else break;
- }
- }
- }
- return rstr;
- }
- //--------------------------------------------
- private String XmlOut(ResultSet oRs , String sRowEntityName,long EntFormat )
- {
- String sSet="";
- try {
- //oRs.first();
- while (oRs.next())
- {
- sSet = sSet + RecordToXMLEntity(oRs, sRowEntityName, EntFormat) ;
- }
- }
- catch (Exception e)
- {
- return e.getMessage();
- }
- return sSet ;
- }
- private String RecordToXMLEntity(ResultSet oRs , String EntityName,long EntFormat)
- {
- String sEty ="";
- int iField=1;
- int iCount=1;
- try {
- ResultSetMetaData rsmd=oRs.getMetaData();
- iCount=rsmd.getColumnCount();
- if (EntFormat==1)
- {
- //属性
- sEty = "<" + EntityName ;
- for (iField = 1 ; iField<=iCount ;iField++ )
- {
- sEty = sEty + " " + rsmd.getColumnName(iField) +"='" + oRs.getString(iField) +"'" ;
- }
- sEty = sEty + "/>" + "n";
- }
- else
- {
- //节点
- sEty = "<" + EntityName +">" +"n" ;
- for (iField = 1 ; iField<=iCount ; iField++)
- {
- sEty = sEty +"<" + rsmd.getColumnName(iField) +">" + oRs.getString(iField) +"</" + rsmd.getColumnName(iField) +">";
- }
- sEty = sEty +"n" +"</" + EntityName +">" +"n";
- }
- }
- catch (Exception e)
- {
- }
- return sEty;
- }
- //-----------------------------------------------------
- private Attr[] sortAttributes(NamedNodeMap attrs) {
- int len = (attrs != null) ? attrs.getLength() : 0;
- Attr array[] = new Attr[len];
- for ( int i = 0; i < len; i++ ) {
- array[i] = (Attr)attrs.item(i);
- }
- for ( int i = 0; i < len - 1; i++ ) {
- String name = array[i].getNodeName();
- int index = i;
- for ( int j = i + 1; j < len; j++ ) {
- String curName = array[j].getNodeName();
- if ( curName.compareTo(name) < 0 ) {
- name = curName;
- index = j;
- }
- }
- if ( index != i ) {
- Attr temp = array[i];
- array[i] = array[index];
- array[index] = temp;
- }
- }
- return(array);
- } // sortAttributes(NamedNodeMap):Attr[]
- private String fcTrans(String sSource)
- {
- //
- //XML节点中的汉字经8859_1==>UTF-8转换后用System.out.println输出正常
- String unicodesR ="";
- try {
- byte [] by = sSource.getBytes("8859_1"); //GB2312
- unicodesR = new String(by,"UTF-8");
- }
- catch (Exception e)
- {
- }
- //System.out.println(unicodesR);
- return unicodesR;
- ///
- }
- //--------------------------------------------
- //WebCode中用
- private String sqltoxml()
- {
- Node root=document.getChildNodes().item(0);
- String strpage=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strsql=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- strsql=fcTrans(strsql);
- String strsearch=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- String strrownum=root.getChildNodes().item(3).getChildNodes().item(0).getNodeValue();
- String showcheckbox=root.getChildNodes().item(4).getChildNodes().item(0).getNodeValue();
- String blnempty=root.getChildNodes().item(5).getChildNodes().item(0).getNodeValue();
- //加空行
- showcheckbox=showcheckbox.toUpperCase();
- int intpage=Integer.parseInt(strpage);//开始页
- int intrownum=Integer.parseInt(strrownum);//页尺寸
- String strX="";
- try {
- //建立数据库连接
- /*
- strDataSource="webgrid";
- strUserName="sa";
- strPassword="";
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:"+strDataSource;
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,strUserName,strPassword);
- Statement stmt = con1.createStatement();
- */
- //原来的
- Statement stmt = con.createStatement();
- //执行查询建立结果集
- //-----------------
- //System.out.print(strsearch);
- int i=1;
- if (strsearch.compareTo("###")!=0){
- rs = stmt.executeQuery(strsql);
- boolean bfind=false;
- while(rs.next()){
- String searchone=rs.getString(1);
- //out.print(searchone);
- if (searchone.equals(strsearch)){
- bfind=true;
- break;
- }
- i=i+1;
- }
- rs.close();
- if (bfind==true){
- if (i<=intrownum){
- intpage=1;
- }
- else {
- if (i%intrownum>0){
- intpage=i/intrownum+1;
- }
- else {
- intpage=i/intrownum;
- }
- }
- }
- //自动定位到当前选择所在值的页
- }
- //out.print("intpage="+intpage);
- //-----------------
- // System.out.print(intpage);
- rs = stmt.executeQuery(strsql);
- ResultSetMetaData rsmd=rs.getMetaData();
- strX="<root>";
- String sLabel="";
- int k=0;
- int thisrow=0;
- int pagenumber=0;//总页数
- int iFind=0; //控制在开始处插入一个空白行
- while (rs.next()) {
- if (blnempty.equals("true") && iFind==0) {
- //插入一个空白行
- strX=strX+"<tr height='16'>";
- for (i=1;i<=rsmd.getColumnCount();i++) {
- strX = strX + "<td></td>";
- }
- strX=strX+"</tr>";
- iFind=1;
- }
- if (k>=(intpage-1)*intrownum && k<(intpage)*intrownum){
- strX = strX + "<tr>";
- for (i=1;i<=rsmd.getColumnCount();i++) {
- sLabel=rsmd.getColumnLabel(i);
- //System.out.println(rsmd.getColumnTypeName(i));
- String sT=rs.getString(i);
- if (sT==null) sT="";
- strX = strX + "<td>" + sT + "</td>";
- }
- if (showcheckbox.equals("TRUE"))
- strX = strX + "<td width='30'><input type='checkbox'></input></td>"+"</tr>";
- else
- strX = strX + "</tr>";
- }
- k=k+1;
- }
- if (k%intrownum>0)
- pagenumber=k/intrownum+1;
- else
- pagenumber=k/intrownum;
- strX=strX+"<pagenumber>"+pagenumber+"</pagenumber><intpage>"+intpage+"</intpage></root>";
- } catch (Exception e){
- strX=e.getMessage();
- }
- return strX;
- }
- }