📄 webprint.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 {
/*
采用tomcat 用自做的连接池建立连接的方法
// String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
// String sConnStr = "jdbc:odbc:ereport";
// Class.forName(sDBDriver);
// con = DriverManager.getConnection(sConnStr,"sa","");
ServletContext application = getServletContext();
//ConnectionManager cm= (ConnectionManager)application.getAttribute("fcConPoolManager");
cm=(ConnectionManager)application.getAttribute ( "fcConPoolManager" );
//demo是配置文件中逻辑数据库的名字,同时也是连接池的名字
con = cm.getConnection( "demo" ); //或者 con = cm.getConnection( "demo", 30000 ); //30000是不能马上取到连接时的等待时间(以毫秒计)
*/
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con=DriverManager.getConnection("jdbc:db2:sample","meiyong","");
} 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语句是否合法
/*
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) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -