Jump to content
JasperReports Library 7.0 is now available ×

Custom Datasource, what's the problem?


javydreamercsw

Recommended Posts

I'm entering the jasper reports from Java tour today and while attemptiing to create my first custom datasource I encountered the following output generated from within the jasper reports classes I'm implementing I suppose:

 

Code:

driver=com.ibm.db2.jcc.DB2Driver@17ace8d
attributes=[Ljava.sql.DriverPropertyInfo;@b0f13d
Resolving properties for: com.ibm.db2.jcc.DB2Driver
user (Required: true)
No choices.
Description: The user name for the connection
password (Required: false)
No choices.
Description: The user's password for the connection

 

Ok, I get I'm somehow missing the username and password but they are provided in the code below:

 

Code:
[code]
/*
* DreamerDataSource.java
*
* Created on April 23, 2007, 3:52 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package iReport.Objects;

import SQLConnection.DBConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

/**
*
* @author javydreamercsw
*/
public class DreamerDataSource implements JRDataSource{
private ResultSet rs=null;
/** Creates a new instance of DreamerDataSource */
public DreamerDataSource(Connection con,String sql) throws SQLException {
setResultSet(con.createStatement().executeQuery(sql));
}
/** Creates a new instance of DreamerDataSource */
public DreamerDataSource(ResultSet rs){
this.setResultSet(rs);
}
/** Creates a new instance of DreamerDataSource */
public DreamerDataSource(){
}

public boolean next() throws JRException {
try {
return getResultSet().next();
} catch (SQLException ex) {
throw new JRException(ex);
}
}

public Object getFieldValue(JRField jRField) throws JRException {
try {
return getResultSet().getObject(jRField.getName());
} catch (SQLException ex) {
throw new JRException(ex);
}
}

public ResultSet getResultSet() {
return rs;
}

public HashMap createHashMapFromResultSet(ResultSet rs, int name,int value){
HashMap hm = new HashMap();
try {
while(rs.next()){
hm.put(rs.getString(name),rs.getObject(value));
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return hm;
}

public static void main(String[] args) {
DreamerDataSource dds= new DreamerDataSource();
dds.createDatasource();
}

public void setResultSet(ResultSet rs) {
this.rs = rs;
}

public JRDataSource createDatasource(){
DBConnection db = new DBConnection("jdbc:db2://10.60.48.110:50000/PW_DATA","user","password",4);
String sql = "select distinct a.material_id,1 from BAX_CONSUMPTION_ST a inner join (select distinct order_id, product_id from BAX_BATCH2_VW " +
"where upper(product_id) like '%') as b on b.order_id=a.batch_id";
DreamerDataSource dds=null;
try {
dds=new DreamerDataSource(db.getConnection(),sql);
} catch (SQLException ex) {
System.err.println("Error"«»);
ex.printStackTrace();
}
return dds;
}
}

 

Where's the error?

 

Thanks in advance!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...