August 20, 2009 by Anand Muranal
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();
}
}
}
Posted in Java | Tagged Crystal report, export to pdf, Java | Leave a Comment »
July 24, 2009 by Anand Muranal
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.
|
Posted in Spring | Tagged difference between struts and spring framework | Leave a Comment »
July 24, 2009 by Anand Muranal
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
Posted in Spring | Tagged AOP, IOC, POJO, Spring DAO, Spring Framework, Spring ORM | 2 Comments »
June 29, 2009 by Anand Muranal
Groovy…
- is an agile and dynamic language for the Java Virtual Machine
- builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
- makes modern programming features available to Java developers with almost-zero learning curve
- supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
- makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
- increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
- simplifies testing by supporting unit testing and mocking out-of-the-box
- seamlessly integrates with all existing Java objects and libraries
- compiles straight to Java bytecode so you can use it anywhere you can use Java
Grails is an open source web application framework which leverages the Groovy programming language (which is in turn based on the Java platform). It is intended to be a high-productivity framework by following the “coding by convention” paradigm, providing a stand-alone development environment and hiding much of the configuration detail from the developer.
Grails has been developed with a number of goals in mind:
- Provide a high-productivity web framework for the Java platform.
- Re-use proven Java technologies such as Hibernate and Spring under a simple, consistent interface
- Offer a consistent framework which reduces confusion and is easy to learn.
- Offer documentation for those parts of the framework which matter for its users.
- Provide what users expect in areas which are often complex and inconsistent:
- Powerful and consistent persistence framework.
- Powerful and easy to use view templates using GSP (Groovy Server Pages).
- Dynamic tag libraries to easily create web page components.
- Good Ajax support which is easy to extend and customize.
- Provide sample applications which demonstrate the power of the framework.
- Provide a complete development mode, including web server and automatic reload of resources.
Grails has been designed to be easy to learn, easy to develop applications and extensible. It attempts to offer the right balance between consistency and powerful features.
Posted in Java | 1 Comment »
June 29, 2009 by Anand Muranal
WATIR, pronounced “Water”, is an acronym standing for “Web Application Testing in Ruby”. Watir is a toolkit used to automate browser-based tests during web application development. This automated test tool uses the Ruby scripting language to drive the Internet Explorer web browser, and is available as a Ruby Gem.
Examples
The google example
# Here we see a very simple WATIR script to drive to google and validate a page
require ‘watir’ # use watir gem
test_site = ‘http://www.google.com’ # set a variable
ie = Watir::IE.new # open the IE browser
ie.goto(test_site) # load url, go to site
ie.text_field(:name, “q”).set(“pickaxe”) # load text “pickaxe” into search field named “q”
ie.button(:name, “btnG”).click # “btnG” is the name of the
# Search button, click it
if ie.text.include?(“Programming Ruby”)
puts “Test Passed. Found the test string: ‘Programming Ruby’.”
else
puts “Test Failed! Could not find: ‘Programming Ruby’”
end
The previous commands can be executed in the Interactive Ruby Shell (irb), or in a Ruby IDE such as FreeRIDE that is installed when Ruby is installed with the once click installer.
Posted in Ruby | Leave a Comment »