Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vicky
java using JSP
1 Answer(s)      5 years and 5 months ago
Posted in : Java Beginners



Advertisement
View Answers

August 24, 2009 at 2:30 PM


Hi Friend,

Try the following code:

1)showExcel.jsp:

<a href="showDataInExcel.jsp">Show datas in Excel format</a>

2)showDataInExcel.jsp:

<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>

<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
PreparedStatement psmnt = null;
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("Select * from student");

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Roll No");
rowhead.createCell((short) 1).setCellValue("Name");
rowhead.createCell((short) 2).setCellValue("Marks");
rowhead.createCell((short) 3).setCellValue("Grade");

int index=1;
while(rs.next()){

HSSFRow row = sheet.createRow((short)index);
row.createCell((short)0).setCellValue(rs.getInt(1));
row.createCell((short)1).setCellValue(rs.getString(2));
row.createCell((short)2).setCellValue(rs.getInt(3));
row.createCell((short)3).setCellValue(rs.getString(4));
index++;
}
File file=new File("c:\\excelFile.xls");
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
out.println("Data is saved in excel file.");

rs.close();
connection.close();
String filePath=file.getAbsolutePath();
Runtime rt = Runtime.getRuntime();
rt.exec("cmd.exe /C start C:\\excelFile.xls");
}
catch(Exception e){}
%>

Thanks


Related Tutorials/Questions & Answers:
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
JSP using java - Java Beginners
JSP using java  sir, In my jsp page contains 3 hyperlinks say (link1 link2 link3).I want to write some java code using servlet for each hyperlinks.how to forward JSP page to servlet.I m using 3 hyperlinks in my page.My
Advertisements
JSP using java - Hibernate
JSP using java  This is my part of Excal sheet code using jdbc connection. int index=1; while(rs.next... using hibernate.I am having function called displayIps() and displayvalues
java using JSP - Java Beginners
java using JSP  hi...i has been created one JSp page.in this page have one links name as "Show datas in Excel format".I want to create Excel file... using postgres DB.This DB have more than 4 Rows and Columns.  Hi Friend
JSP using java - Java Beginners
JSP using java  hi, In my jsppage has Combo box(contains inpacks...). I have core java code for (inpacks,outpacks,system uptime etc... inpacks from combo box and clicking bar chart options concurrently in the jsp
Java using Jsp - Java Beginners
Java using Jsp  hi sir, 1)showExcel.jsp: Show datas in Excel... and executed in netbeans 4.1. but not work in EclipseEE.i m using Tomcat server 6 .I m included JAR file also.After executing the jsp page shows
java using jsp - Java Beginners
java using jsp  i already included those jar file into my library in eclipse.i previously send my JSP code.But it shows error like. type... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred
JSP using java - Java Beginners
JSP using java  hi...i has been created one JSp page.in this page have one links name as "Show datas in PDF format".I want to create PDF file which containing datas(from database interaction) when i clicking that link...i m using
JSP using java - Java Beginners
JSP using java  I want to generate chart in JSP page.My bar chart code contains the following function String series1 = "bars"; dataset.addValue(Integer.parseInt(values.get(i)),series1,(String)Values1.get(i
Java using Jsp - Java Beginners
Java using Jsp  hi sir, again i m getting error like. HSSFWorkbook cannot be resolved to a type. HSSFSheet cannot be resolved to a type. HSSFRow cannot be resolved to a type I included Maximum all jar file in eclipse
Register page using servlets,jsp and java beans
Register page using servlets,jsp and java beans  i want code for register page using jsp,serlets and java beans.iam getting error for my code in java...://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml Thanks
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
Project on mailing system using Java/JSP
Project on mailing system using Java/JSP  I am making a project on mailing system in Java/JSP. How could I display the inbox messages on the home page of user? Please tell me about how to handle these messages in database
deploy jsp using web logic - Java Beginners
deploy jsp using web logic  Hi all, I am new in Web logic server please tell me what is the steps of writing deployee the jsp using web logic. and steps also arrange the folder its urgent
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
Error in using java beans - JSP-Servlet
Error in using java beans  I am getting the following error when I run the jsp code. type Exception report message description The server...: Unable to load class for JSP
Could not able to run Java Applet in JSP using <jsp:plugin>
Could not able to run Java Applet in JSP using   I could not able to run the above example applet in the JSP. Getting class not found exception... the following links: http://www.roseindia.net/jsp/applet-jsp.shtml http
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
online test project on java using servlets and jsp
online test project on java using servlets and jsp  as i am doing online test project on java using jsp and servlets ,,,the problem is in the code of jsp file which i have sent,...,i used next and previous buttons and used two
Doubt in using combination of JSP page and Java class. - JSP-Servlet
Doubt in using combination of JSP page and Java class.   I've got... be disabled from clicking. How to go about doing this in a "JSP Page using a Pure Java class"? The Database table looks like this: SeatCode
remote procedure call using java - JSP-Servlet
remote procedure call using java  what is the romote procedure call and related coding in java?  Hi Friend, The RPC (Remote Procedure...: 1. A java program invokes a method on a stub, 2. Stub invokes routines
SMS alert system using Java - JSP-Servlet
SMS alert system using Java  Respected Sir/Mam, I need to develop an SMS alert application. Scope of the application: Basically... recipients. This can be developed using any kind of componentsThanks
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
How to export web page to excel using java or jsp or servlets
How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am... errors. Please can anyone tell me how to do this using java or jsp or servlets
need a sample project using java technologies like jsp, servlets, struts
need a sample project using java technologies like jsp, servlets, struts  Hi everybody! I have learnt core java,jdbc,jsp,servlets & struts... other project with detailed explanation using the above technologies by which i
Using Beans in JSP. A brief introduction to JSP and Java Beans.
USING BEANS IN JSP           Java Beans Java Beans are reusable components
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp code college.jsp page <HTML> <head> </head> <body>... using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp code college.jsp page <HTML> <head> </head> <body>... using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp code college.jsp page <HTML> <head> </head> <body>... using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp code college.jsp page <HTML> <head> </head> <body>... using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp code college.jsp page <HTML> <head> </head> <body>... using this jsp,but i want to CollegeAction class and CollegeForm class how to do
 

 

 

DMCA.com