1、客户端对服务器端的pdf文件进行自动打印需要的包有commons-codec-1.6.jarcommons-logging-1.1.3.jarhttpclient-4.3.3.jarhttpclient-cache-4.3.3.jarhttpcore-4.3.2.jarhttpmime-4.3.3.jarlog4j-1.2.15.jarojdbc6.jarpdfbox-app-1.8.5.jar代码如下:import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import jav
2、ax.swing.JOptionPane;public class ConnOracle public static Connection getConnectionOracle(String user, String password, String urlIp, String sid) throws ClassNotFoundException, SQLException Connection con = null; Class.forName(oracle.jdbc.driver.OracleDriver); String url = jdbc:oracle: + thin: + url
3、Ip + : + sid; con = DriverManager.getConnection(url, user, password); return con; /* * * 中利用定数。 * * */public class Constants public static final String TYOUHYOU_ID = TYOUHYOU_ID; public static final String RIYOUKANNSYO_CD = RIYOUKANNSYO_CD; public static final String LOCAL_PDF_BASYO = LOCAL_PDF_BASY
4、O; public static final String SERVER_PDF_BASYO = SERVER_PDF_BASYO; public static final String DB_USER_ID = DB_USER_ID; public static final String DB_SID = DB_SID; public static final String DB_PASSWORD = DB_PASSWORD; public static final String DB_URL = DB_URL; public static final String TAJYUUKIDOU_
5、ERROR = 多重起動:要確認; public static final String SONOTA = sonota; public static final String SONOTA_UNCOMP = sonota_uncomp; public static final String TYOUHYOUJIDOUSYUTURYOKU = 帳票自動出力処理実行; public static final String TEYIJI = 提示; public static final String HOUTEI = houtei; public static final String HOUT
6、EI_UNCOMP = houtei_uncomp; public static final String PDF = pdf; public static final String JPG = .jpg; public static final String C_PATH_TMP = C:/batch/tmp; public static final String LOG_FILE = lastTime.txt; public static final String START_FILE = start.txt; public static final String DB_ERROR = D
7、B接続時発生; public static final String INTERNET_ERROR = 接続; public static final String PRINT_ERROR = 接続、自動印刷処理中断。; public static final String JIDOUPRINT_ERROR = 自動印刷処理中断; public static final String PDFPRINT_ERROR = PDF印刷途中発生; public static final String PRINT_IP = PRINT_IP; public static final String APP
8、_INTERVAL = APP_INTERVAL; public static final String PROFILEPATH = C:batchconfigAutoPrint.conf; public static final String STARTTXTJIKANGSETE = C:/batch/tmp配下lastTime.txt日付時間設定。(日付時間yy-MM-dd HH:mm:ss.SSSSSS);import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;impor
9、t java.sql.SQLException;import java.sql.Timestamp;import java.util.ArrayList;import java.util.List;public class Dao public String getFirstMaxTime(Connection conn, String hoyukansho_cdStr, String chohyo_idstr) throws SQLException String firstMaxTime = null; PreparedStatement pre = null; ResultSet res
10、ult = null; String sql = select max(to_char(tazzm208.shutsuryoku_date) + from tazzm208 + where tazzm208.hoyukansho_cd in (_IN_STRING2_) .replaceFirst(_IN_STRING2_, hoyukansho_cdStr); sql = sql + and tazzm208.chohyo_id in (_IN_STRING_).replaceFirst( _IN_STRING_, chohyo_idstr); try pre = conn.prepareS
11、tatement(sql); result = pre.executeQuery(); while (result.next() firstMaxTime = result.getString(1); finally try if (result != null) result.close(); if (pre != null) pre.close(); if (conn != null) conn.close(); catch (Exception e) e.printStackTrace(); return firstMaxTime; public List getOutputpath(C
12、onnection conn, String hoyukansho_cdStr, String chohyo_idstr, String maxTimeStr, String previousTimeStr) throws SQLException PreparedStatement pre = null; ResultSet result = null; String sql = ; List outputpathList = new ArrayList(); if (previousTimeStr = null) sql = select tazzm208.outputpath, + ta
13、zzm208.chohyo_id , + to_char(tazzm208.shutsuryoku_date) + from tazzm208 + where to_char(tazzm208.shutsuryoku_date) = ? + and tazzm208.hoyukansho_cd in (_IN_STRING2_) .replaceFirst(_IN_STRING2_, hoyukansho_cdStr); sql = sql + and tazzm208.chohyo_id in (_IN_STRING_) .replaceFirst(_IN_STRING_, chohyo_i
14、dstr); else sql = select tazzm208.outputpath, + tazzm208.chohyo_id , + to_char(tazzm208.shutsuryoku_date) + from tazzm208 + where to_char(tazzm208.shutsuryoku_date) ? + and tazzm208.hoyukansho_cd in (_IN_STRING2_) .replaceFirst(_IN_STRING2_, hoyukansho_cdStr); sql = sql + and tazzm208.chohyo_id in (
15、_IN_STRING_) .replaceFirst(_IN_STRING_, chohyo_idstr); try pre = conn.prepareStatement(sql); pre.setString(1, maxTimeStr); if (previousTimeStr != null) pre.setString(2, previousTimeStr); result = pre.executeQuery(); while (result.next() String outputpath = result.getString(1); String chohyo_id = res
16、ult.getString(2); String shutsuryoku_date = result.getString(3); String record = new String3; record0 = outputpath; record1 = chohyo_id; record2 = shutsuryoku_date; outputpathList.add(record); finally try if (result != null) result.close(); if (pre != null) pre.close(); if (conn != null) conn.close(
17、); catch (Exception e) e.printStackTrace(); return outputpathList; /* * * param conn * param chohyo_idp * param shutsuryoku_date * return * throws SQLException */ public String getCheckOutputpathResult(Connection conn, String chohyo_idparam, String shutsuryoku_dateparam) throws SQLException Prepared
18、Statement pre = null; ResultSet result = null; String outputpathStr = null; String sql = select tazzm208.outputpath + from tazzm208 + where tazzm208.chohyo_id = ? + and to_char(tazzm208.shutsuryoku_date) = ? ; try pre = conn.prepareStatement(sql); pre.setString(1, chohyo_idparam); pre.setString(2, s
19、hutsuryoku_dateparam); result = pre.executeQuery(); while (result.next() String outputpath = result.getString(1); outputpathStr = outputpath; finally try if (result != null) result.close(); if (pre != null) pre.close(); if (conn != null) conn.close(); catch (Exception e) e.printStackTrace(); return
20、outputpathStr; import java.awt.image.BufferedImage;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IO
21、Exception;import java.io.InputStream;import .ConnectException;import java.sql.Connection;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import javax.imageio.ImageIO;import javax.print.Doc;import javax.print.DocFlavor;import javax.print.DocPrintJob;import javax.print.Pr
22、intException;import javax.print.PrintService;import javax.print.PrintServiceLookup;import javax.print.SimpleDoc;import javax.print.attribute.DocAttributeSet;import javax.print.attribute.HashDocAttributeSet;import javax.print.attribute.HashPrintRequestAttributeSet;import javax.print.attribute.standar
23、d.MediaPrintableArea;import javax.print.attribute.standard.MediaSizeName;import javax.print.attribute.standard.OrientationRequested;import javax.swing.JOptionPane;import org.apache.http.HttpResponse;import org.apache.http.StatusLine;import org.apache.http.client.ClientProtocolException;import org.ap
24、ache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.log4j.Logger;import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.pdmodel.PDPage;public class MyThread extends Thread boolean printFlag =
25、false; private static Logger logger = Logger.getLogger(MyThread.class); public void run() BufferedWriter bw = null; BufferedReader input = null; BufferedReader inputstatus = null; File status = new File(C:/batch/status); File filestatus = new File(status, status.txt); List checkoutputpathresult = ne
26、w ArrayList(); List outputpathNotNull = new ArrayList(); logger.info(二重起動); / 二重起動 / 1以下存在、存在場合二重起動見表示、処理中断 / 二重起動:【】tmpstart.txt File filepathstart = new File(Constants.C_PATH_TMP); File filestart = new File(filepathstart, Constants.START_FILE); if (filestart.exists() logger.info(*二重起動*); / 表示、処理中断
27、 / :”多重起動:要確認” Object options = OK ; JOptionPane.showOptionDialog(null, Constants.TAJYUUKIDOU_ERROR, Constants.TEYIJI, JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options0); System.exit(0); while (true) try try inputstatus = new BufferedReader(new FileReader(filestatus); String statusStr = ; String statusread = inputstatus.readLine(); if (statusread != null) statusStr = statusread; if (500.equals(statusStr) inputstatus.close(); logger.info(処理中断); Ob
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1