高手!求助!!!
我的问题是:
下边是我的部分代码:
package yinshua;import java.awt.Color;import java.awt.Font;import java.io.File;import java.io.FileInputStream;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JTable;import org.xml.sax.SAXParseException;import com.fr.base.Constants;import com.fr.base.FRContext;import com.fr.base.FRFont;import com.fr.base.Style;import com.fr.data.DatasourceManager;import com.fr.report.CellElement;import com.fr.report.Report;import com.fr.report.io.TemplateImporter;import com.fr.view.PreviewFrame;public class CpcAllPrint { public CpcAllPrint(String sql0,String table1) throws SQLException{ File cptFile = new File("d:\\report\\cpcall.cpt");//这是你生成的那个模板的存放路径 try { try{ TemplateImporter templateImporter = new TemplateImporter(cptFile); Report workSheet = templateImporter.generateReport(); Statement rst1=Sqlconn.getStatement(); ResultSet ab1=rst1.executeQuery(sql0); int d = 0; while (ab1.next()){ int a= Integer.parseInt(ab1.getString(1)); d=a; } String table="create table #cpkucun1" + "(" + "id int identity(1,1) not null," + "cpc_num int null," + "Production_code varchar(50) null," + "Production_name varchar(50) null," + "Production_city varchar(20) null," + "Time char(10) null," + "cpc_time char(20) null," + "cpc_shuliang int null," + "Production_unit varchar(50) null," + "Single_prince float null," + "cpc_jine float null," + "Invoice_code varchar(50) null," + "Production_specification char(30) null," + "Start varchar(50) null," + "End1 varchar(50) null," + "Note varchar(50) null" + ")"; Statement rst4=Sqlconn.getStatement(); rst4.addBatch(table); rst4.addBatch(table1); rst4.executeBatch(); for(int i=0;i<16;i++){ for(int j=0;j<=d;j++){ String sql1="select * from #cpkucun1 where id='"+j+"'"; Statement rst2=Sqlconn.getStatement(); ResultSet ab2=rst2.executeQuery(sql1); while (ab2.next()){ CellElement cellElement= new CellElement(0+i,4+j,ab2.getString(1+i)); Style style = cellElement.getStyle(); if(style == null) { style = Style.getInstance(); } style = style.deriveBorder(Constants.LINE_THIN,Color.black,Constants.LINE_THIN,Color.black,Constants.LINE_THIN,Color.black,Constants.LINE_THIN,Color.black); style = style.deriveHorizontalAlignment(Constants.CENTER); //边框的颜色和粗细 style = style.deriveVerticalAlignment(Constants.BOTTOM); cellElement.setStyle(style); workSheet.addCellElement(cellElement); } } } Sqlconn.getStatement().executeUpdate("drop table #cpkucun1"); String datasourceFilePath = "d:\\report\\datasource.xml";//设置数据源管理器,只需要读取datasource.xml文件即可 FileInputStream datasourceFileInputStream = new FileInputStream(datasourceFilePath); DatasourceManager datasourceManager = new DatasourceManager(); datasourceManager.readInputStreamXML(datasourceFileInputStream); FRContext.getFRContext().setDatasourceManager(datasourceManager); Report excuteReport = workSheet.execute(); PreviewFrame previewFrame1 = new PreviewFrame(); previewFrame1.print(excuteReport); previewFrame1.setVisible(true); } catch(SAXParseException e) {e.printStackTrace();} } catch(Exception e) { e.printStackTrace(); } }}
......
出现了不期望的字符.
[解决办法]
字符有问题,是不是数据库字符集设置的问题?
[解决办法]
字符问题!
[解决办法]
at yinshua.CpcAllPrint. <init>(CpcAllPrint.java:87)
不知道你的 哪行是87行,应该是这个位置出的问题,你仔细检查检查!