Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    34
    Rep Power
    2
    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
  2. #17
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    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?
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    34
    Rep Power
    2
    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
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    34
    Rep Power
    2
    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>
    }
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    34
    Rep Power
    2
    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 !
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo