Thursday, 20 August 2009

Export Crystal Report to PDF by using Java Program


Here I am using some crystal report which will connect to database and fetch the data to create report.
It will expect username and password from the calling function.
Also it will expect some parameter(Name) from the calling function. Below is the code
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Date;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.*;
import com.crystaldecisions.sdk.occa.report.data.Connections;
import com.crystaldecisions.sdk.occa.report.data.Fields;
import com.crystaldecisions.sdk.occa.report.data.IConnection;
import com.crystaldecisions.sdk.occa.report.data.ParameterField;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
public class ReportExport {
public static void main(String[] args) {
try {
String report_name = “D://path/crystalReportName.rpt”;
String exportFileName = “D://path/outputFileName.pdf”;
ReportClientDocument clientDoc =  new ReportClientDocument();
clientDoc.open(report_name, ReportExportFormat._PDF);
//Connecting Database through crystal report
clientDoc.getDatabaseController().logon(“user_name”, “password”);
//Passing Parameter(Name) to Crystal Report
clientDoc.getDataDefController().getParameterFieldController().setCurrentValue(“”, “Name”,”anand”);
//Writing into PDF file
ByteArrayInputStream bais = (ByteArrayInputStream) clientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
int size = bais.available();
byte[] barray = new byte[size];
FileOutputStream fos = new FileOutputStream(new File(exportFileName));
ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
int bytes = bais.read(barray, 0, size);
baos.write(barray, 0, bytes);
baos.writeTo(fos);
clientDoc.close();
bais.close();
baos.close();
fos.close();
dbConn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Friday, 24 July 2009

Spring Framework


Spring is standard in lightweight enterprise application framework. Layered architecture, which allows you to be selective about which of its components you use there are seven modules in Spring Frame work
I>  Spring Core:
Uses IOC pattern to separate the application configuration with dependency specification from the actual application code.
IOC (Inversion of control)
  • No creation of object but describe how to create
  • Not connect direct to components
  • Mention in conf file for which service which component
  • org.springframework.beans
Bean Factory
  • org.springframework.beans.factory.BeanFactory
  • Singletone mode: Shared instance
  • Prototype Mode: each retrieval result new object
  • Take care when to create objects and when to invoke the method
Java Beans -  POJO ()
  • No creation of object but describe how to create
II>  Spring Context:
  • Context Information
  • EJB, e-mail, internalization, validation, and scheduling functionality.
III>  Spring AOP (Aspect Oriented Programming):
  • Provides transaction management services for objects
  • Logging (declaratively to the components that required logging.)
IV> Spring DAO (Data Access Object):
  • managing the exception handling
  • error messages
  • opening and closing connections
V > Spring ORM
  • Including JDO, Hibernate, and iBatis SQL Maps.
VI>  Spring Web Module
  • The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.
VII > Spring MVC framework:
  • Numerous view technologies including JSP, Velocity, Tiles

Difference between Struts and Spring


Sl. No
Struts
Spring
1
Struts is a web framework
Spring is an application
framework
2
Using MVC pattern
spring MVC is one of the
modules
3
Hard code to use applications
like hibernate, JDBC
Inbuilt hibernate, JDBC etc
4
Struts allows only JSP
Support JSPs, Velocity,
Free maker etc.,
5
Struts is heavy weight
Spring is light weight
6
Struts is tightly coupled
Spring is loosely coupled.
7
Excellent support for
Tag Library
Not that Much
8
Easy to integrate with other
client side technologies
Not Easy.

Wednesday, 18 March 2009

Example : MultiActionController in Spring


1> Controller Contains
public class testController extends MultiActionController {
public ModelAndView action_name1(HttpServletRequest          httpServletRequest,HttpServletResponse httpServletResponse) {
System.out.println(“In Action1″);
return new ModelAndView(“view1″, “date”,”date”);
}
public ModelAndView action_name2(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
System.out.println(“In Action 2″);
return new ModelAndView(“view2″, “date”,”date”);
}
}
2> View contains
<a href=”test.htm?action=action_name1″ >Go to Action1 </a> |
<a href=”test.htm?action=action_name2″ >Go to Action2 </a>
3> Change in Application-servlet.xml
<bean name=”/test.htm” class=”testController”>
<property name=”methodNameResolver”>
<ref bean=”paramResolver”/>
</property>
</bean>
<bean id=”paramResolver” class=”org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver”>
<property name=”paramName”><value>action</value></property>
</bean>
Simple Way:
1> Controller Contains
same as above
2> View contains
<a href=”test.htm/action_name1″ >Go to Action1 </a> |
<a href=”test.htm/action_name2″ >Go to Action2 </a>
3> Change in Application-servlet.xml
No need to add anything

Wednesday, 18 February 2009

Error : svnserve.conf:12: Option expected svnserve.conf

In svnserve.conf, you cannot have a space before you set an argument and a variable. It doesn’t find the argument. Open svnserve.conf and delete extra spaces at the beginning of any line.