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:
  #1  
Old November 16th, 2012, 11:09 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
Servlets/JSP - How to print report using multiple unique numbers(primary keys)

i have a project where , the system is supposed to print an excel report based on the franchise no, month and year.
as of now my project print the excel report only if you key in one franchise number , moth , year.
I would like to know how my servlet can accept different franchise numbers, separated by commas and prints an excel report with all the franchise results ..here is my index and servlet.

here is the servlet

public class reportexcel extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
@Override
public void destroy() {
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);

}

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

PrintWriter out = response.getWriter();

out.print( request.getRequestURI() );



out.close();


}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
HSSFWorkbook wb = new HSSFWorkbook ();
HSSFSheet sheet = wb.createSheet("Mighty Report");

out.print("\t\tMighty Auto Part Report\n");
out.print("Franchise ID");
out.print("\tFranchise Name");
out.print("\tMonth\tyear");
out.print("\tESR V");
out.print("\tReported Values");
out.print("\tDifference\n");

Statement st2= null;
Statement st3 = null;
Statement st4 = null;

ResultSet rs2;
ResultSet rs3;
ResultSet rs4;

try {
Connection con;
Connection conn;

Class.forName("org.postgresql.Driver").newInstance();
con = DriverManager.getConnection("jdbcostgresql://216.77.96.20:5432/ESR","postgres","postgres");
conn = DriverManager.getConnection("jdbcostgresql://216.77.96.20:5432/FranchiseDB","postgres","postgres");

st2 = conn.createStatement();
st3 = con.createStatement();
st4 = con.createStatement();


String franno = request.getParameter("franno");
String month = request.getParameter("month");
String year = request.getParameter("year");


//Returns names of the franchises based on the farnchise number
String query2 = "Select corpname from franchise where frannum = '"+franno+"'order by frannum";

// to print ESR VALUES
String query3 = "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 ESRVALUE, 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) = '"+month+"' and date_part('year',inv_date) = '"+year+"' and franno::integer in ('"+franno+"') group by franno, salesmonth,salesyear order by franno";
//to print Reported Values
String query4 = "select franno, sum(territory + custodial) as reported,salesmonth,salesyear from salesdata,salesperson where salesperson.mightyspid = salesdata.mightyspid and salesmonth = '"+month+"' and salesyear = '"+year+"' and franno::integer in ('"+franno+"') group by franno,salesmonth,salesyear order by franno";

rs2 = st2.executeQuery(query2);
rs3 = st3.executeQuery(query3);
rs4 = st4.executeQuery(query4);



if(rs2.next()){
out.print(""+franno+"");
out.print("\t");
out.print(""+rs2.getString(1)+"");
out.print("\t");
out.print(""+month+"");
out.print("\t");
out.print(""+year+"");
out.print("\t");

if (rs3.next()){
out.print(rs3.getDouble(2)+"");
out.print("\t");
if (rs4.next()){
out.print(rs4.getDouble(2)+"");
out.print("\t");
double diff = 0.0;
diff = (rs3.getDouble(2) - rs4.getDouble(2));
out.print(diff);
}

FileOutputStream fileOut = new FileOutputStream("c:\\excelFile.xls");
wb.write(fileOut);
fileOut.close();
out.print("\n");
}
}

}
catch (Exception e) {
out.print(e);
out.print("<p\"><a href=\"");
out.print( request.getRequestURI() );
out.print("\">Back</a></p>");
//out.print("</body></html>");
out.close();
}


}
}

here is the index..
<html>
<body>
<form action="reportexcel" method="post">

<table border="0" width="300" align="center" bgcolor="#CDFFFF">
<tr><td colspan=2 style="font-size:12pt;color:#00000;" align="center"><h3>Search Record</h3></td></tr>
<tr><td ><b>franchise Number</b></td><td>: <input type="text" name="franno" id="franno">
</td></tr>
<tr><td ><b>month</b></td><td>: <input type="text" name="month" id="month">
</td></tr>
<tr><td ><b>year</b></td><td>: <input type="text" name="year" id="year">
</td></tr>
<tr><td colspan=2 align="center"><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>

Reply With Quote
  #2  
Old November 16th, 2012, 01:07 PM
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,826 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 9 h 52 m 17 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
You could modify your index file to ask to a list of franchise numbers seperated by a comma. Then in the servlet, tokenize the input (split it into seperate Strings), and then perform the query for each.

Reply With Quote
  #3  
Old November 16th, 2012, 01:40 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
thank you

Quote:
Originally Posted by bullet
You could modify your index file to ask to a list of franchise numbers seperated by a comma. Then in the servlet, tokenize the input (split it into seperate Strings), and then perform the query for each.


Thank you bullet , i have never used tokens and delimiters but let me do a quick research and get back to you

Reply With Quote
  #4  
Old November 16th, 2012, 01:50 PM
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,826 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 9 h 52 m 17 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
Thank you bullet , i have never used tokens and delimiters but let me do a quick research and get back to you


Look at the JavaDocs for String.java

Reply With Quote
  #5  
Old November 16th, 2012, 02:08 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
invalid input syntax for integer: "140,381 "

Quote:
Originally Posted by bullet
Look at the JavaDocs for String.java


this is what i changed part of my code in the servlet to look like and it gave me an error

//this is supposed to display the franchise number
String franno = request.getParameter("franno");
String[] tokens = franno.split(",");
for (int i = 0; i<tokens.length; i++){
out.print(tokens[i]+"");}

Reply With Quote
  #6  
Old November 16th, 2012, 02:26 PM
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,826 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 9 h 52 m 17 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
this is what i changed part of my code in the servlet to look like and it gave me an error

//this is supposed to display the franchise number
String franno = request.getParameter("franno");
String[] tokens = franno.split(",");
for (int i = 0; i<tokens.length; i++){
out.print(tokens[i]+"");}


What error did it give you?

Reply With Quote
  #7  
Old November 16th, 2012, 02:28 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
What error did it give you?

invalid input syntax for integer: "140,381"

Reply With Quote
  #8  
Old November 16th, 2012, 05:07 PM
itsjonlin itsjonlin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 7 itsjonlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 31 m 22 sec
Reputation Power: 0
Helpppppppppppp

hey guys, can u check this code and tell me y, these two javascripts arent working together, if i open it in a browser
the comments sections works and the twitter doesnt but when i refresh the page the tiwtter works and the comments doesnt
i didnt align anything so it seems sporadic
i just need help getting the two scripts to work properly


i would post the code but for some reason url's are blocked

sry i am new to forums
Comments on this post
stdunbar disagrees: (-0) Start a new post, don't hijack an exising one

Reply With Quote
  #9  
Old November 16th, 2012, 10:29 PM
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,826 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 9 h 52 m 17 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
invalid input syntax for integer: "140,381"


Are you sure that's the error you get from that code?

Reply With Quote
  #10  
Old November 17th, 2012, 07:12 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
Are you sure that's the error you get from that code?

yes this is the error i get , when i run my index file and key in the different user inputs,and submit to the servlet

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Servlets/JSP - How to print report using multiple unique numbers(primary keys)

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