Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old November 12th, 2012, 10:33 AM
nicholas.omosa nicholas.omosa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 nicholas.omosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 5 sec
Reputation Power: 1
Quote:
Originally Posted by bullet
When you say you run, how exactly do you go about running it?

am using netbeans . on the project tab i have my project called mighty, i right click on it and choose run

Reply With Quote
  #17  
Old November 12th, 2012, 10:57 AM
bullet's Avatar
bullet bullet is online now
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,820 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 8 h 11 m 43 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Quote:
Originally Posted by nicholas.omosa
there are two ways,
1) i run the main project, then it gives me this error:
The requested resource (/mighty/NewServlet) is not available.

2) i run only the servlet then it asks for the url which in this case its mighty/NewServlet ...............mighty is the package name, NewServlet is the servlet name..then it just shows a white page .


Have you tried modifying your web.xml to use /mighty/NewSerlvet as the pattern instead of /NewServlet?

Reply With Quote
  #18  
Old November 12th, 2012, 11:03 AM
nicholas.omosa nicholas.omosa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 nicholas.omosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 5 sec
Reputation Power: 1
Quote:
Originally Posted by bullet
Have you tried modifying your web.xml to use /mighty/NewSerlvet as the pattern instead of /NewServlet?


yes i have in a short while i will be pasting the a new servlet that is meant to export data to an excel file

Reply With Quote
  #19  
Old November 12th, 2012, 11:25 AM
nicholas.omosa nicholas.omosa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 nicholas.omosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 5 sec
Reputation Power: 1
Quote:
Originally Posted by nicholas.omosa
yes i have in a short while i will be pasting the a new servlet that is meant to export data to an excel file



here is the servlet to export data to excel
package mighty;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


/**
*
* @author nomosa
*/
@WebServlet(name = "NewServlet1", urlPatterns = {"/NewServlet1"})
public class NewServlet1 extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
@Override
public void destroy() {
}
//connnects to the first databse (ESR)
public static Connection getConnection(String db){
Connection con = null;
try{
Class.forName("org.postgresql.Driver").newInstance();
con = DriverManager.getConnection("jdbcostgresql://216.77.96.20:5432/ESR" + db ,"postgres","postgres");

}catch (Exception ex){ }
return con;
}
//connects to the second database(FRNACHISE DB)
public static Connection getConnection2(String db){
Connection conn = null;
try{
Class.forName("org.postgresql.Driver").newInstance();
conn = DriverManager.getConnection("jdbcostgresql://216.77.96.20:5432/FranchiseDB" + db ,"postgres","postgres");

}catch (Exception ex){ }
return conn;
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");

HSSFWorkbook wb = new HSSFWorkbook ();
HSSFSheet sheet = wb.createSheet("new sheet");

PrintWriter out = response.getWriter();

Statement st = null;
Statement st2= null;
Statement st3 = null;
Statement st4 = null;
Statement st5 = null;

try {
System.out.println("Connected to the database");
String franno = request.getParameter("franno");
String month = request.getParameter("month");
String year = request.getParameter("year");

//Array List to pint franchise number, month , year according to the user input
String query = "select * from ticket where franno ='"+franno+"' and month='"+month+"' and year='"+year+"'order byfranno";
System.out.println("query " + query);

//Returns names of the franchises based on the farnchise number
String query4 = "Select corpname from franchise where frannum = '"+franno+"'order byfranno";
System.out.println("query4 " + query4);

//array list to print ESR VALUES

String query2 = "select franno, sum((ticket.sub_nontax + ticket.sub_tax + ticket.misc + ticket.disc + ticket.core_nontax + ticket.core_tax) - getxlinebycust(ticket.cust_id, ticket.inv_num::integer, date(ticket.inv_date))) AS ear-sales, date_part('month',inv_date) as salesmonth , date_part('year',inv_date) as salesyear from ticket, salesperson where ticket.mightyspid = salesperson.mightyspid and date_part('month',inv_date) = ? and date_part('year',inv_date) = ? and franno::integer in (?) group by franno, salesmonth,salesyear order by franno";
System.out.println("query2 " + query2);

//Array List to print Reported Values

String query3 = "select franno,sum(territory +custodial) as reported,salesmonth,salesyear from salesdata,salesperson where salesperson.mightyspid = salesdata.mightyspid and salesmonth = ? and salesyear = ? franno::integer in (?) group by franno,salesmonth,salesyear order by franno";
System.out.println("query3 " + query3);


//ArraylIST TO Print difference in ESR-REPORTED
//Note that is not a set difference, and won't output items in result2 that don't exist in result3. It's set subtraction.
String query5 = "select DISTINCT rs2.column FROM rs21 LEFT JOIN rs2 ON rs3.column = rs2.column WHERE rs2.column IS NULL order by franno";
System.out.println("query5" + query5);


Connection con = getConnection("//216.77.96.20/ESR)");
st = con.createStatement();
st2 = con.createStatement();
st3 = con.createStatement();
st5 = con.createStatement();


Connection conn= getConnection2("//216.77.96.20:5432/FranchiseDB");
st4 = conn.createStatement();

HSSFRow row = sheet.createRow((short)0);

ResultSet rs = st.executeQuery(query);
int index= 1;
while(rs.next()){
//CREATE CELLS
HSSFCell cell = row.createCell(0);
HSSFCell cell5 = row.createCell(0);
HSSFCell cell6 = row.createCell(0);

cell.setCellValue(rs.getString(1));
cell5.setCellValue(rs.getString(3));
cell6.setCellValue(rs.getString(4));
index++;
}
int index2 = 1;
ResultSet rs2 = st2.executeQuery(query2);
while (rs2.next() ){
// HSSFRow row = sheet.createRow((short)0);
HSSFCell cell2 = row.createCell(0);
cell2.setCellValue(rs2.getString(5));
index2++;
}

int index3 = 1;
ResultSet rs3 = st3.executeQuery(query3);
while (rs3.next() ){
HSSFCell cell3 = row.createCell(0);
cell3.setCellValue(rs3.getString(6));
index3++;
}

int index4= 1;
ResultSet rs4 = st4.executeQuery(query4);
while (rs4.next()){
HSSFCell cell4 = row.createCell(0);
cell4.setCellValue(rs4.getString(2));
index4++;
}

int index5= 1;
ResultSet rs5 = st5.executeQuery(query5);
while (rs5.next()){
HSSFCell cell7 = row.createCell(0);
cell7.setCellValue(rs5.getString(7));
index4++;
index5++;
}

FileOutputStream fileOut = new FileOutputStream("c:\\excelFile.xls");
wb.write(fileOut);
fileOut.close();
out.println("Data is saved in excel file.");
con.close();
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
}
}

@Override
public String getServletInfo() {
return "report for Mighty Auto!!!!";
}// </editor-fold>
}

Reply With Quote
  #20  
Old November 12th, 2012, 02:51 PM
nicholas.omosa nicholas.omosa is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 nicholas.omosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 5 sec
Reputation Power: 1
Quote:
Originally Posted by bullet
When you say you run, how exactly do you go about running it?


i was able to solve the error, i posted a new error that am facing now.. Please check it out.
Thank you bullet ! i appreciate it !

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Servlets/JSP - How to export data from servlet to excel file through poi lib

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap