no reply yet

I collected the data off the form and placed it in a bean class, DataBean.

JRBeanCollectionDataSource constructor takes Collection as parameter, so i should convert the bean data into some kind of collection, like list, and then pass it into JRBeanCollectionDataSource and pass its instance to JasperManager.fillReport method.

In iReport "$F(fieldName) notation" will be $F(bean properties name)

Here is the code

List<DemandSlipEntity> l = new ArrayList<DemandSlipEntity>();  
l.add(dse);  
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(l);  
InputStream in = this.getClass().getClassLoader().getResourceAsStream("reports/Demand Slip.jasper");  
 try {  
    System.out.println("insidse try");  
    JasperPrint jpr = JasperFillManager.fillReport(in, null, ds);  
    //JasperExportManager.exportReportToPdfFile(jpr, "C:\\demand.pdf");  
        JasperViewer.viewReport(jpr, false);  

    } catch (JRException e1) {  
            // TODO Auto-generated catch block  
            e1.printStackTrace();  
    }  

where dse is the instance of DemandSlipEntity class. In demand Slip.jasper i have used the properties of DemandSlipEntity, such as $F{name}, where name is a property of DemandSlipEntity.

This code gives the following exception :

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach  
e/commons/beanutils/PropertyUtils  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProp  
erty(JRAbstractBeanDataSource.java:115)  
        at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldVal  
ue(JRAbstractBeanDataSource.java:100)  
        at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldV  
alue(JRBeanCollectionDataSource.java:104)  
        at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDat  
aset.java:822)  
        at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.jav  
...................  
....................  

I have added commons-beanutils to the classpath, but still same problem

But, all other reports are running. I have a separate file for report. What i did is just included a report (from that reports file,which is running fine) in my swing file, just to get a receipt kind of report

No. The program doesn't works correct in GUI mode. I ran it into console to find out exception if any.

No reply ?

I have created an application using swing. On clicking a particular menu item, a form is loaded,and after saving it a pdf generates. For reporting, i am using iReport. Here is the code snippet

MyiReportViewer.java

package sms.ui.ireport;  

import java.awt.BorderLayout;  
import java.awt.Container;  
import java.io.InputStream;  
import java.sql.Connection;  
import java.sql.DriverManager;  
import java.sql.SQLException;  
import java.util.HashMap;  
import net.sf.jasperreports.engine.JRException;  
import net.sf.jasperreports.engine.JasperFillManager;  
import net.sf.jasperreports.engine.JasperPrint;  
import net.sf.jasperreports.swing.JRViewer;  

public class MyiReportViewer extends javax.swing.JInternalFrame {  

   private MyiReportViewer()  
{  
super("Report Viewer",true,true,true,true);  
initComponents();  
setBounds(10,10,600,500);  
setDefaultCloseOperation(DISPOSE_ON_CLOSE);  
}  

   public MyiReportViewer(InputStream stream,HashMap parameter)  
{  
this();  
try  
{  
    if(stream==null){  
        System.out.println("Null stream");  

    }  
/* load the required JDBC driver and create the connection 
here JDBC Type Four Driver for MySQL is used*/  
Class.forName("oracle.jdbc.driver.OracleDriver");  
Connection con =  
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","school","school");  
/*(Here the parameter file should be in .jasper extension 
i.e., the compiled report)*/  

JasperPrint print = JasperFillManager.fillReport(  
stream, parameter, con);  
JRViewer viewer=new JRViewer(print);  
Container c=getContentPane();  
c.setLayout(new BorderLayout());  
c.add(viewer);  
}  
catch(ClassNotFoundException cnfe)  
{  
cnfe.printStackTrace();  
}  
catch(SQLException sqle)  
{  
sqle.printStackTrace();  
}  
catch(JRException jre)  
{  
jre.printStackTrace();  
}  
}  

   public MyiReportViewer(InputStream stream)  
{  
this(stream,null);  
}  

    @SuppressWarnings("unchecked")  
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                            
    private void initComponents() {  

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
        getContentPane().setLayout(layout);  
        layout.setHorizontalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGap(0, 394, Short.MAX_VALUE)  
        );  
        layout.setVerticalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGap(0, 274, Short.MAX_VALUE)  
        );  

        pack();  
    }// </editor-fold>                          

    // Variables declaration - do not modify                       
    // End of variables declaration                     

}  

My swing class

//some code & after the user clicks submit button in the form, this code runs  
                                       desktopPane = new javax.swing.JDesktopPane();  

                        String input = JOptionPane.showInputDialog("Enter the Batch (yyyy)");  
                         if (input != null) {  
                          try {  
                            int batch = Integer.parseInt(input);  
                            HashMap parameters = new HashMap(); ...

Thanks urtrivedi. i have came up with a solution. Its

select A.id, A.summed, B.summed  
from   
(select id, sum(amount) summed from A where id = 1 group by id) A  
left join  
(select id, sum(amount) as summed from B where id = 1 group by id) B  
on A.id = B.id

create table A (
id number(6)
, Amount number(10)
);

create table B (
id number(6)
, Amount number(10)
);

insert into A values (1, 50);
insert into A values (2, 500);
insert into A values (1, 600);
insert into A values (2, 900);
insert into A values (1, 600);

insert into B values (2, 30);
insert into B values (1, 300);
insert into B values (1, 100);
insert into B values (1, 900);
insert into B values (1, 770);

This is what i want
id = 1
sum(A.amount) = 1250
sum(B.amount) = 2070
(offcourse, a single row)

This gives wrong data :
select sum(A.amount),sum(B.amount) from A,B where A.id = B.id and A.id = 1

select A.id,sum(A.amount),sum(B.amount) from A,B where A.id = B.id(+) and A.id = 1 group by A.id

The wrong output is

id = 1
sum(A.amount) = 5000
sum(B.amount) = 6210
(offcourse, a single row)

The reason for wrong output is, that the no. of rows with id 1 in table A differs from the no. of rows with id 1 in table B

I tried

SELECT * FROM (
SELECT ID, SUM(amount) FROM A WHERE id=1
INNER JOIN
SELECT ID, SUM(amount) FROM B where id=1
ON A.id = B.id )

But it gives "ORA - 00907 - missing right parenthesis" error

What should i do?

Okay..Thanks a lot NormR1. :)

But still, i wonder, why it doesn't works in IDE

Yes, different than jar. Is this the reason?

Stranger thing is that, the code doesn't works in IDE, but, when i converted it into .exe, it works fine. All modules (even report) works fine. Still wonder , why?

But, the value is null. Spelling is also correct

sorry. I changed the file name. It still gives the NullPointerException
and the file path is correct
D:\HIbernate 26th April\FinalStudent\reports\Student's Detail.jasper
D: is the location
HIbernate 26th April- name of workspace
FinalStudent - name of project
reports folder contains all .jasper files

Tried this :

File f = new File("reports/Student's Detail.jasper");
System.out.println(f.getAbsolutePath());

It prints
D:\HIbernate 26th April\FinalStudent\reports\Student's Detail.jasper
HIbernate 26th April- name of workspace
FinalStudent - name of project
reports folder contains all .jasper files

structure of the project (in IDE)

FinalStudent
--src
------org.nit.Entity
------org.nit.Dao
............
............
reports
----all .jasper files

But, the file exists...

The caller of this constructor passes a file as a stream

InputStream in = this.getClass().getClassLoader().getResourceAsStream("reports/StaffDetail.jasper");

                    MyiReportViewer myiReportViewer = new MyiReportViewer(
                            in, parameters);

Yes NormR1. Parameter passed to MyiReportViewer constructor is null...
This verifies it :

public MyiReportViewer(InputStream stream,HashMap parameter)
{
this();
try
{
    if(stream==null){
        System.out.println("Null stream");

    }
//some codes

I have created an application with report features. report features is created via iReport
My application also contains a reports folder containing all .japser files

Here is the code

public MyiReportViewer(InputStream stream,HashMap parameter)  
{  
this();  
try  
{  
/* load the required JDBC driver and create the connection 
here JDBC Type Four Driver for MySQL is used*/  
Class.forName("oracle.jdbc.driver.OracleDriver");  
Connection con =  
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hibernate","hibernate");  
/*(Here the parameter file should be in .jasper extension 
i.e., the compiled report)*/  
JasperPrint print = JasperFillManager.fillReport(  
stream, parameter, con);  
JRViewer viewer=new JRViewer(print);  
Container c=getContentPane();  
c.setLayout(new BorderLayout());  
c.add(viewer);  
}  
catch(ClassNotFoundException cnfe)  
{  
cnfe.printStackTrace();  
}  
catch(SQLException sqle)  
{  
sqle.printStackTrace();  
}  
catch(JRException jre)  
{  
jre.printStackTrace();  
}  
}  

   public MyiReportViewer(InputStream stream)  
{  
this(stream,null);  
}  

*(Another (calling) class)

 private void studentReportEnrActionPerformed(java.awt.event.ActionEvent evt) {                                                   
            String input = JOptionPane.showInputDialog("Enter the Student Enrollment No");  
            if (input != null) {  
                try {  
                    long enrollMentNo = Long.parseLong(input);  
                    HashMap parameters = new HashMap();  
                    System.out.println(enrollMentNo);  
                    parameters.put("EnrollmentNo", enrollMentNo);  
                    InputStream in = getClass().getResourceAsStream("reports/Student's Detail.jasper");  
                    MyiReportViewer myiReportViewer = new MyiReportViewer(in, parameters);  
                    myiReportViewer.setBounds(  
                            0, 0, desktopPane.getWidth(), desktopPane.getHeight());  
                    myiReportViewer.setVisible(true);  
                    desktopPane.add(myiReportViewer);  
                    myiReportViewer.setSelected(true);  
                } catch (PropertyVetoException pve) {  
                    pve.printStackTrace();  
                } catch (NumberFormatException nfe) {  
                    JOptionPane.showMessageDialog(  
                            this, "Please input numbers only");  
                }  
            }  
        }                    

This throws the following exception :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2266)
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:57)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:197)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:380)
at sms.ui.ireport.MyiReportViewer.<init>(MyiReportViewer.java:53)
..................
..................

Line no 53 of MyiReportViewer is :
JasperPrint print = JasperFillManager.fillReport(
stream, parameter, con);

The stream passed in line no 53 is null. (verified by an if condition)

How should i correct it

I have a login page, which directs to Verification.jsp

Login.jsp

[CODE]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<form action="Verification.jsp" method="POST">
<fieldset>
<a rel="nofollow">FreeLancer? Sign up!</a> <br/>
<input type="radio" name="r1" value="Admin" checked="checked"/>Admin<br/>
<input type="radio" name="r1" value="Editors"/>Editor<br/>
<input type="radio" name="r1" value="Staff"/>Journalist<br>
<input type="radio" name="r1" value="Staff"/>Reporter<br/>
<input type="radio" name="r1" value="Freelancers"/>Freelancer<br/>
<br/>
<br/>
USERNAME : <input type="text" name="t1"/><br>

PASSWORD : <input type="password" name="t2" />
<p/><input type="submit" value="Login">
<input type="reset">

</fieldset>   
</form>   

</body>
</html>

[/CODE]

EveryThing in Login.jsp and verification.jsp is working fine.

I am having a STAFF table, which contains data of JOURNALIST & REPORTER. So, to differentiate their ID, i have a column STYPE, which contains 'R' for Reporter, and 'J' for journalist.

So, when Reporters logs in, i need 'R' to be generated, so that i can provide STYPE in my Query.

How to do this.?
If i place An attribute 'Id' in radio buttons in Login.jsp, how can i get this Id when the radio button is selected??

Verification.jsp

[CODE]

<%@ page language='java' import='java.sql.,java.lang.' %>

<%
try {
String str="";
String user=request.getParameter("r1");
String username=request.getParameter("t1");
String password=request.getParameter("t2");

if(user=="Staff"){   
    str="Select * from " +user+ " where username='"+username+"' and password='"+password+"' and stype='"***"' "; //here i need Id of reporter/journalist based on login//   
}   
else  
{   
str="Select * from " +user+ " where username='"+username+"' and password='"+password+"'";   
}   

if(username.trim().length()!=0 && password.trim().length()!=0)   
{   
    Class.forName("oracle.jdbc.driver.OracleDriver");   
    Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger");   
    Statement st=conn.createStatement();   
    ResultSet rs=st.executeQuery(str);   

System.out.println(str);
int c=0;
if(rs.next())
{
c++;
session.setAttribute("user",user);
session.setAttribute("username",rs.getString("username"));
}
st.close();
conn.close();

    if(c==0)    
    {   
        session.setAttribute("msg","INVALID USERNAME/PASSWORD");   
        response.sendRedirect("errorpage.jsp");   
    }   
    else {   
    response.sendRedirect("frame.jsp");   
    }   
}   
else { ...

I am having a column named 'AREA' in a table named Editors. I am now making a html page for Staffs. In that page, i am having a field named 'AREA OF WORKING'. I have to retrieve values from AREA column of EDITORS table, and have to give the same areas to staffs in a list. So, that the staff can choose his area. So, i can't hardcode the values in HTML page.

So, how to proceed with the above mentioned problem?