hai frnd..........
on clicking the print button goto a new jsp page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">;
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="
http://java.sun.com/jsp/jstl/core"; prefix="c"%>
<html>
<head>
<title>SEARCH</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<form>
<%@ page import="java.sql.*" %>
<%! Connection con;
ResultSet rst;
Statement st;
int a=0,no_of_pages=0,int count=o;
String url="jdbc:db2://url/database:";
%>
<%
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
con=DriverManager.getConnection(url,"db2inst2","inst123$");
System.out.println("After Establishing connection");
}
catch(ClassNotFoundException e)
{
System.out.println("ERROR!1: "+e);
}
%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="java.io.*" %>
<%try{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);
try
{
st=con.createStatement();
System.out.println("Before Select");
rst=st.executeQuery("select * from tablename");
System.out.println("After select");
while(rst.next())
{
row.createCell((short)1).setCellValue(rst.getInt(1));//write according to ur column datatype
row.createCell((short)2).setCellValue(rst.getString(2));//write according to ur cloumn datatype.
//write the same command for how many columns u want to save in excel
row.createCell((short)3).setCellValue(true);
FileOutputStream fileOut = new FileOutputStream
("c:\\excel\\Data.xls");
wb.write(fileOut);
fileOut.close();
}catch ( Exception ex ){
}
%>
<br>
<b>The Data is saved to Excel</b>
</form>
</bodY>
</html>
Thanks and Regards
Prashu
[email protected]