- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在寻找此问题的解决方案时遇到了问题。我的代码运行后工作正常。它应该将我的 sql 数据库中的数据显示到我的 jtable,并且有一个按钮会触发显示 jasper 报告,但有一点问题,它总是向我显示消息“文档没有页面”。这是为什么?有人可以帮我解决我的问题吗?我做错了什么?
这是我的代码:
package stringmanipulation;
import java.sql.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
public class r2xml extends javax.swing.JFrame {
public r2xml() {
initComponents();
}
Connection con;
private void search() throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:*****";
String user = "******";
String pass = "******";
Connection con = DriverManager.getConnection(url, user, pass);
Statement state = con.createStatement();
ResultSet rs = state.executeQuery("SELECT "
+ "pIDNo AS 'Patient ID',"
+ "pLName AS 'Last Name',"
+ "pFName AS 'First Name',"
+ "pMI AS 'M.I.',"
+ "pSex AS 'Sex',"
+ "pStatus AS 'Status',"
+ "pTelNo AS 'Contact No.',"
+ "pDocID AS 'Doctor ID',"
+ "pAddr AS 'St. No.',"
+ "pStreet AS 'St. Name',"
+ "pBarangay AS 'Barangay',"
+ "pCity AS 'City',"
+ " pProvince AS 'Province',"
+ " pLNameKIN AS 'Last Name',"
+ "pFNameKIN AS 'First Name',"
+ "pMIKIN AS 'M.I.',"
+ "pRelationKIN AS 'Relation',"
+ "pTotalDue AS 'Total Due'"
+ " FROM dbo.Patients");
ResultSetMetaData rsmetadata = rs.getMetaData();
int columns = rsmetadata.getColumnCount();
DefaultTableModel dtm = new DefaultTableModel();
Vector column_name = new Vector();
Vector data_rows = new Vector();
for (int i=1; i<columns;i++){
column_name.addElement(rsmetadata.getColumnName(i));
}
dtm.setColumnIdentifiers(column_name);
while(rs.next()){
data_rows = new Vector();
for (int j=1; j<columns; j++){
data_rows.addElement(rs.getString(j));
}
dtm.addRow(data_rows);
}
tblPatient.setModel(dtm);
}
public void reportviewer() {
try{
String report = "C:\\Users\\cleanfuel\\Documents\\NetBeansProjects\\StringManipulation\\src\\stringmanipulation\\report1.jrxml";
JasperReport jasp_report = JasperCompileManager.compileReport(report);
JasperPrint jasp_print = JasperFillManager.fillReport(jasp_report, null, con);
JasperViewer.viewReport(jasp_print);
}
catch (Exception e) {System.out.print(e);}
}
@SuppressWarnings("unchecked")
public static void main(String args[]) {
PatternLayout pl = new PatternLayout("[%-5p] %C.%M:%L: %m%n");
ConsoleAppender appender = new ConsoleAppender(pl);
Logger.getRootLogger().addAppender(appender);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new r2xml().setVisible(true);
}
});
}
这是 XML 报告:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="null" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="71"/>
<style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false" pdfFontName="Times-Bold"/>
<style name="SubTitle" forecolor="#666666" fontName="Times New Roman" fontSize="18" isBold="false" pdfFontName="Times-Roman"/>
<style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true" pdfFontName="Times-Roman"/>
<style name="Detail" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman"/>
<style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#F0EFEF"/>
</conditionalStyle>
</style>
<subDataset name="PieChartDataset"/>
<queryString language="SQL">
<![CDATA[SELECT
Patients."pIDNo" AS Patients_pIDNo,
Patients."pLName" AS Patients_pLName,
Patients."pFName" AS Patients_pFName,
Patients."pMI" AS Patients_pMI,
Patients."pSex" AS Patients_pSex,
Patients."pStatus" AS Patients_pStatus,
Patients."pTelNo" AS Patients_pTelNo,
Patients."pDocID" AS Patients_pDocID,
Patients."pAddr" AS Patients_pAddr,
Patients."pStreet" AS Patients_pStreet,
Patients."pBarangay" AS Patients_pBarangay,
Patients."pCity" AS Patients_pCity,
Patients."pProvince" AS Patients_pProvince,
Patients."pLNameKIN" AS Patients_pLNameKIN,
Patients."pFNameKIN" AS Patients_pFNameKIN,
Patients."pMIKIN" AS Patients_pMIKIN,
Patients."pRelationKIN" AS Patients_pRelationKIN,
Patients."pTotalDue" AS Patients_pTotalDue
FROM
"dbo"."Patients" Patients]]>
</queryString>
<field name="Patients_pIDNo" class="java.lang.String"/>
<field name="Patients_pLName" class="java.lang.String"/>
<field name="Patients_pFName" class="java.lang.String"/>
<field name="Patients_pMI" class="java.lang.String"/>
<field name="Patients_pSex" class="java.lang.String"/>
<field name="Patients_pStatus" class="java.lang.String"/>
<field name="Patients_pTelNo" class="java.lang.String"/>
<field name="Patients_pDocID" class="java.lang.String"/>
<field name="Patients_pAddr" class="java.lang.String"/>
<field name="Patients_pStreet" class="java.lang.String"/>
<field name="Patients_pBarangay" class="java.lang.String"/>
<field name="Patients_pCity" class="java.lang.String"/>
<field name="Patients_pProvince" class="java.lang.String"/>
<field name="Patients_pLNameKIN" class="java.lang.String"/>
<field name="Patients_pFNameKIN" class="java.lang.String"/>
<field name="Patients_pMIKIN" class="java.lang.String"/>
<field name="Patients_pRelationKIN" class="java.lang.String"/>
<field name="Patients_pTotalDue" class="java.math.BigDecimal"/>
<group name="Patients_pIDNo">
<groupExpression><![CDATA[$F{Patients_pIDNo}]]></groupExpression>
<groupHeader>
<band height="31">
<frame>
<reportElement mode="Opaque" x="72" y="7" width="730" height="24" forecolor="#B89F7D" backcolor="#70A9C6"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="SubTitle" isPrintRepeatedValues="false" x="155" y="1" width="110" height="23" forecolor="#FFFFFF"/>
<textElement>
<font fontName="Arial" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pIDNo}]]></textFieldExpression>
</textField>
</frame>
</band>
</groupHeader>
<groupFooter>
<band height="6"/>
</groupFooter>
</group>
<background>
<band height="555" splitType="Stretch">
<pie3DChart>
<chart isShowLegend="false" evaluationTime="Report">
<reportElement x="-18" y="406" width="229" height="139"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<dataset>
<datasetRun subDataset="PieChartDataset">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
</datasetRun>
</dataset>
<keyExpression><![CDATA[/* Replace with your key expression here */
$V{REPORT_COUNT}]]></keyExpression>
<valueExpression><![CDATA[new Double(200*Math.random()*5)]]></valueExpression>
</pieDataset>
<pie3DPlot>
<plot backgroundAlpha="0.5" foregroundAlpha="0.8">
<seriesColor seriesOrder="0" color="#3399FF"/>
<seriesColor seriesOrder="1" color="#00CCFF"/>
<seriesColor seriesOrder="2" color="#0066CC"/>
<seriesColor seriesOrder="3" color="#6699FF"/>
<seriesColor seriesOrder="4" color="#004A94"/>
<seriesColor seriesOrder="5" color="#00356A"/>
</plot>
<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
</pie3DPlot>
</pie3DChart>
<image>
<reportElement x="-20" y="65" width="229" height="250">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER} == 1]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["flower1.png"]]></imageExpression>
</image>
<image>
<reportElement x="-20" y="-20" width="229" height="250">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER} > 1]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["flower1.png"]]></imageExpression>
</image>
<staticText>
<reportElement mode="Opaque" x="318" y="315" width="239" height="181" backcolor="#FFFFCC">
<printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
</reportElement>
<box topPadding="4" leftPadding="4" bottomPadding="4" rightPadding="4">
<pen lineWidth="1.0" lineColor="#CC9900"/>
<topPen lineWidth="1.0" lineColor="#CC9900"/>
<leftPen lineWidth="1.0" lineColor="#CC9900"/>
<bottomPen lineWidth="1.0" lineColor="#CC9900"/>
<rightPen lineWidth="1.0" lineColor="#CC9900"/>
</box>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[Each chart is populated on each page.
The 3 pie charts are currently using an empty datasource and the values are
generated using a random generator.
This rectangle element is not printed (see the print when expression of this
element)]]></text>
</staticText>
<line>
<reportElement x="201" y="431" width="117" height="1">
<printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
</reportElement>
<graphicElement>
<pen lineWidth="3.0" lineStyle="Dotted" lineColor="#996600"/>
</graphicElement>
</line>
<staticText>
<reportElement mode="Opaque" x="275" y="-10" width="240" height="181" backcolor="#FFFFCC">
<printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
</reportElement>
<box topPadding="4" leftPadding="4" bottomPadding="4" rightPadding="4">
<pen lineWidth="1.0" lineColor="#CC9900"/>
<topPen lineWidth="1.0" lineColor="#CC9900"/>
<leftPen lineWidth="1.0" lineColor="#CC9900"/>
<bottomPen lineWidth="1.0" lineColor="#CC9900"/>
<rightPen lineWidth="1.0" lineColor="#CC9900"/>
</box>
<textElement markup="none">
<font size="12"/>
</textElement>
<text><![CDATA[Flowers
There are two flowers, the first one is printed only starting from the second page, the other one only in the first page.]]></text>
</staticText>
<line>
<reportElement x="72" y="37" width="204" height="1">
<printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
</reportElement>
<graphicElement>
<pen lineWidth="3.0" lineStyle="Dotted" lineColor="#996600"/>
</graphicElement>
</line>
</band>
</background>
<title>
<band height="94" splitType="Stretch">
<staticText>
<reportElement style="SubTitle" x="336" y="65" width="449" height="29"/>
<textElement textAlignment="Right">
<font size="22" isBold="false"/>
</textElement>
<text><![CDATA[Hospital ]]></text>
</staticText>
<frame>
<reportElement mode="Opaque" x="-20" y="0" width="822" height="65" forecolor="#006699" backcolor="#006699"/>
<staticText>
<reportElement style="Title" x="231" y="0" width="578" height="65"/>
<textElement textAlignment="Right">
<font size="54" isBold="false"/>
</textElement>
<text><![CDATA[Patient Form]]></text>
</staticText>
</frame>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="14" splitType="Stretch">
<frame>
<reportElement x="210" y="0" width="575" height="14"/>
<staticText>
<reportElement style="Column header" positionType="Float" x="99" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pSex]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="132" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pStatus]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="165" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pTelNo]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="198" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pDocID]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="231" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pAddr]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="264" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pStreet]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="297" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pBarangay]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="330" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pCity]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="363" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pProvince]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="396" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pLNameKIN]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="429" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pFNameKIN]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="462" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pMIKIN]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="495" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pRelationKIN]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="528" y="0" width="33" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Patients_pTotalDue]]></text>
</staticText>
</frame>
<staticText>
<reportElement style="Column header" positionType="Float" x="0" y="0" width="72" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[ Last Name]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="72" y="0" width="65" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[First Name]]></text>
</staticText>
<staticText>
<reportElement style="Column header" positionType="Float" x="137" y="0" width="74" height="14" forecolor="#000000"/>
<textElement>
<font fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica"/>
</textElement>
<text><![CDATA[Middle Initial]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="15" splitType="Stretch">
<line>
<reportElement positionType="FixRelativeToBottom" x="227" y="14" width="575" height="1"/>
</line>
<frame>
<reportElement x="226" y="0" width="575" height="14"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="99" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pSex}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="132" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pStatus}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="165" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pTelNo}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="198" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pDocID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="231" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pAddr}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="264" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pStreet}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="297" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pBarangay}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="330" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pCity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="363" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pProvince}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="396" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pLNameKIN}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="429" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pFNameKIN}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="462" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pMIKIN}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="495" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pRelationKIN}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="528" y="0" width="33" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pTotalDue}]]></textFieldExpression>
</textField>
</frame>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="4" y="0" width="68" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pLName}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="72" y="1" width="65" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pFName}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Detail" positionType="Float" x="137" y="1" width="72" height="14"/>
<textElement>
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[$F{Patients_pMI}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="7" splitType="Stretch">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
</band>
</columnFooter>
<pageFooter>
<band height="16" splitType="Stretch">
<frame>
<reportElement mode="Opaque" x="2" y="0" width="800" height="16" forecolor="#D0B48E" backcolor="#006699"/>
<textField evaluationTime="Report">
<reportElement style="Column header" x="753" y="0" width="40" height="16" forecolor="#FFFFFF"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Column header" x="673" y="0" width="80" height="16" forecolor="#FFFFFF"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement style="Column header" x="2" y="0" width="197" height="16" forecolor="#FFFFFF"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="12" isBold="false" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
最佳答案
首先,资源管理...
如果可以的话,你应该只打开一个到数据库的连接。确保在关闭应用程序之前关闭它。连接过程可能很昂贵,因此您只有在绝对必要时才真正想这样做...
您在使用完资源后关闭它们。这最好通过使用 try-finally
block 来实现...
private Connection con;
protected void close() throws SQLException {
if (con != null) {
con.close();
}
}
protected Connection getConnection() throws ClassNotFoundException, SQLException {
if (con == null) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:*****";
String user = "******";
String pass = "******";
Connection con = DriverManager.getConnection(url, user, pass);
}
return con;
}
private void search() throws Exception {
Statement state = null;
ResultSet rs = null;
try {
state = getConnection().createStatement();
rs = state.executeQuery("SELECT "
+ "pIDNo AS 'Patient ID',"
+ "pLName AS 'Last Name',"
+ "pFName AS 'First Name',"
+ "pMI AS 'M.I.',"
+ "pSex AS 'Sex',"
+ "pStatus AS 'Status',"
+ "pTelNo AS 'Contact No.',"
+ "pDocID AS 'Doctor ID',"
+ "pAddr AS 'St. No.',"
+ "pStreet AS 'St. Name',"
+ "pBarangay AS 'Barangay',"
+ "pCity AS 'City',"
+ " pProvince AS 'Province',"
+ " pLNameKIN AS 'Last Name',"
+ "pFNameKIN AS 'First Name',"
+ "pMIKIN AS 'M.I.',"
+ "pRelationKIN AS 'Relation',"
+ "pTotalDue AS 'Total Due'"
+ " FROM dbo.Patients");
ResultSetMetaData rsmetadata = rs.getMetaData();
int columns = rsmetadata.getColumnCount();
DefaultTableModel dtm = new DefaultTableModel();
Vector column_name = new Vector();
Vector data_rows = new Vector();
for (int i = 1; i < columns; i++) {
column_name.addElement(rsmetadata.getColumnName(i));
}
dtm.setColumnIdentifiers(column_name);
while (rs.next()) {
data_rows = new Vector();
for (int j = 1; j < columns; j++) {
data_rows.addElement(rs.getString(j));
}
dtm.addRow(data_rows);
}
tblPatient.setModel(dtm);
} finally {
try {
rs.close();
} catch (Exception e) {
}
try {
state.close();
} catch (Exception e) {
}
}
}
现在解决手头的问题......
看来您已经创建了两个对 con
的引用。一个作为类字段,一个作为方法变量(在 search
中)。
然后您将 con
传递给 Jasper Reports,我怀疑它是 null
。相反,您应该使用上面概述的 getConnection()
。
public void reportviewer() {
try{
String report = "C:\\Users\\cleanfuel\\Documents\\NetBeansProjects\\StringManipulation\\src\\stringmanipulation\\report1.jrxml";
JasperReport jasp_report = JasperCompileManager.compileReport(report);
JasperPrint jasp_print = JasperFillManager.fillReport(jasp_report, null, getConnection());
JasperViewer.viewReport(jasp_print);
} catch (Exception e) {
e.printStackTrace();
}
}
与后台 worker 更新...
一份报告可能需要一些时间来编译和填写。您应该将这项工作卸载到后台线程,这样它就不会干扰您的 UI(或者让它看起来像您的应用程序挂起)。
最简单的解决方案是使用 SwingWorker
。它具有将线程与 UI 重新同步的功能
public void reportviewer() {
// Disable any UI components you don't want the user using while
// the report generates...
new ReportWorker().execute();
}
public class ReportWorker extends SwingWorker<JasperPrint, Void> {
@Override
protected JasperPrint doInBackground() throws Exception {
String report = "C:\\Users\\cleanfuel\\Documents\\NetBeansProjects\\StringManipulation\\src\\stringmanipulation\\report1.jrxml";
JasperReport jasp_report = JasperCompileManager.compileReport(report);
JasperPrint jasp_print = JasperFillManager.fillReport(jasp_report, null, getConnection());
return jasp_print;
}
@Override
protected void done() {
try {
JasperPrint jasp_print = get();
JasperViewer.viewReport(jasp_print);
} catch (Exception exp) {
exp.printStackTrace();
}
// Renable any UI components you disabled before the report run
}
}
看看Concurrency in Swing了解更多详情。
提示
如果您可以预编译报告并加载它(而不是加载 XML),它将使报告过程更快。
关于java - 该文档没有页面。碧 Jade 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15964552/
我有一个 .sln 文件,里面有几个项目。为了简单起见,让我们称它们为... 项目A 项目B 项目C ...其中 A 是引用 B 和 C 的主要项目。我的目标是更新我的构建脚本,为 ProjectA
我安装了 Magento,我想知道如何生成完整的 API 文档,例如 http://docs.magentocommerce.com/ 上的文档是使用 phpdoc 生成的。 Magento 中是否包
我通常使用jetbrains family ide。在为函数创建文档时非常有用,只需输入 /** 如何在创建文档时创建自定义标签,例如@date标签。 最佳答案 JavaScript、Java: st
我正在尝试使用 jOpenDocument library创建文档。我已经执行了创建电子表格的示例 - 代码编译并运行正常,但当我尝试使用 Excel Office 2012 或 Google Doc
如标题。 有没有介绍HTML DOM构造的图片? 最佳答案 DOM(文档 对象模型)从文档 节点开始。它被称为“根节点”。 观察下面的树(括号中对应的nodeType): [HTMLDocument]
我喜欢 ColdFusion Builder。但我不喜欢帮助只有 CF9 文档。有什么方法可以将其更改为拥有 ColdFusion 8 文档? 最佳答案 http://livedocs.adobe.c
这个问题在这里已经有了答案: What is the consequence of this bit of javascript? (4 个答案) 关闭 9 年前。 我看到一些 jQuery 脚本嵌
我有一个 XML 文件,其中包含需要在 Word 文档中填充的数据。 我需要找到一种方法来定义一个模板,该模板可用作从 XML 文件填充数据并创建输出文档的基线。 我相信有两种方法可以做到这一点。 创
我正在尝试查找有关如何使用 AVAudioEngine 的详细文档。有谁知道我在哪里可以找到它? 我找到了这个,但与文档丰富的 UI 内容相比,它似乎非常简陋。 https://developer.a
我对 Tensorflow 文档越来越感到恼火和沮丧。我在谷歌上搜索了有关 的文档 tf.reshape 我被定向到一个通用页面,例如 here 。我想查看 tf.reshape 的详细信息,而不是整
我正在学习本教程:http://moxleystratton.com/clojure/clojure-tutorial-for-the-non-lisp-programmer 然后遇到了这个片段: u
如何在 swagger 中为对象数组编写文档。这是我的代码,但我不知道如何访问对象数组中的数据。 { "first_name":"Sam", "last_name":"Smith",
是否有针对 Javascript 的 JavaDocs 之类的东西?当我在 netbeans IDE 中按 ctrl+space 时 写javascript,指定对象的javascript文档就出来了
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我需要 JavaScript 中的 heredoc 之类的东西。你对此有什么想法吗?我需要跨浏览器功能。 我发现了这个: heredoc = '\ \ \ zzz\ \
WSDL 文档是包含一系列的,可描述某个 web service 的定义的,简单的 XML 文档 WSDL 文档结构 WSDL 文档用下表这些主要的元素来描述某个 web service 的
是否有 ocropus 的文档? 我正在寻找对以下功能的解释: make_SegmentPageByRAST(): segment() RegionExtractor(): setPageLines(
这个问题在这里已经有了答案: Understanding events and event handlers in C# (13 个回答) 4年前关闭。 我正在使用 NRECO 和 ffmpeg 对视
我正在尝试访问工作服务器以与名为 Spotfire 的应用程序一起使用。我的同事把这个传给我,现在已经休息了几个星期,我对他的建议有意见。 实际上,当我通过 localhost 运行我的 Web 应用
Elm 文档没有给出示例用法,因此很难理解类型规范的含义。在几个地方,我看到“a”用作参数标识符,例如 Platform.Cmd : map : (a -> msg) -> Cmd a -> Cmd
我是一名优秀的程序员,十分优秀!