Ragini Shukla
Hiiii
2 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners

View Answers

August 22, 2008 at 2:16 PM


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
prashobvee@gmail.com

August 22, 2008 at 2:18 PM


hai frnd....
CLOSE THE WHILE LOOP BEFORE FileOutputStream fileOut = new FileOutputStream
("c:\\excel\\Data.xls");


Thanks and regards
Prashu
prashobvee@gmail.com









Related Pages:
input using scanner and add/sub/mul/div of a matrix
input using scanner and add/sub/mul/div of a matrix  hiiii...... performe matrix add/sub/mul/div using scanner
RAJ9992
Servlet sending image  hiiii In my html page i use how to send this image value to servlet plz be inform me anybody
RAJ9992
Send Image Value to Servlet  hiiii In my html page i use input type=image src="" value="" name="" how to send this image value to servlet plz be inform me anybody
login data
login data   Hiiii Sir I am doing banking project on Asp.net i have created database on sql and also created a connection to gui but m not getting the data after login i want to show particular data for particular user means
login data
login data  Hiiii Sir I am doing banking project on Asp.net i have created database on sql and also created a connection to gui but m not getting the data after login i want to show particular data for particular user means if i
error in accessing database - JSP-Servlet
error in accessing database  hiiii im tanushri im tryng to connect my database to the servlet i hv succeeded in connectivity but im stuck to nother error called Got minus one from read call although i hv feeded data to my
error got minus one from read call - JSP-Servlet
error got minus one from read call  hiiii while connecting my servlet to database im getting error called java.sql.SQLException: Io exception: Got minus one from a read call oracle.jdbc.dbaccess.DBError.throwSqlException

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.