Want to display from database but javaclas not returning values to servlets

I am trying to view values stored in database using jsp, servlets and java class. Jsp is calling servlet and servlet calls java class file. and javaclass file retrieves data from database and sends it back to servlet. But my problem is servlet doesnt print the values.
Here is my code
This is the javaclass file.
package pack;
import java.util.*;
import java.sql.Driver.*;
import java.sql.Connection.*;
import java.sql.*;
import java.sql.DriverManager.*;
import java.sql.SQLException.*;
import java.io.*;
import java.io.Serializable;
import java.util.Vector;
import pack.ser1;
/* Control is got from the servlet file */
public class employbean implements Serializable
  public Vector result;
  public Vector getResult() throws ClassNotFoundException, InstantiationException, IllegalAccessException
            /* Connection is established to retrieve data from the database */
            Vector v = new Vector();
            ResultSet rs = null;
            PreparedStatement st = null;
            try
             Class.forName("org.gjt.mm.mysql.Driver").newInstance();
             Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?user=user&password=password");
              st = connection.prepareStatement("Select * from samp");
              rs = st.executeQuery();
              while(rs.next())
                  v.addElement(rs.getString("empid"));
              st.close();
              connection.close();
             catch(SQLException esql)
                  esql.printStackTrace();
              this.result = v;
             /* Control is sent back to the servlet */
             return result;
}Here is the servlet code.
package pack;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import pack.employbean;
import java.util.Enumeration;
import java.util.Vector;
import pack.*;
public class ser1 extends HttpServlet
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try
          employbean ebean = new employbean();
          Vector v = ebean.getResult();
          Enumeration en = v.elements();
          while(en.hasMoreElements())
            out.println("employee id= "+ en.nextElement());
          out.println("employid"+employid);
         catch(Exception m)
           out.println(m);
         out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    /** Returns a short description of the servlet.
    public String getServletInfo()
        return "Short description";
}Please help me with my code as where i might have gone wrong and help me rectifying the errors.
I also would like to know if this is MVC pattern.
Thanks in Advance

Try this one
package pack;
import java.util.*;
import java.sql.Driver.*;
import java.sql.Connection.*;
import java.sql.*;
import java.sql.DriverManager.*;
import java.sql.SQLException.*;
import java.io.*;
import java.io.Serializable;
import java.util.Vector;
import pack.ser1;
/* Control is got from the servlet file */
public class employbean implements Serializable
public Vector result;
public Vector getResult() throws Exception
/* Connection is established to retrieve data from the database */
Vector v = new Vector();
ResultSet rs = null;
PreparedStatement st = null;
try
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?user=user&password=password");
st = connection.prepareStatement("Select * from samp");
rs = st.executeQuery();
while(rs.next())
v.addElement(rs.getString("empid"));
st.close();
connection.close();
catch(SQLException esql)
     throw e;
this.result = v;
/* Control is sent back to the servlet */
return result;
Here is the servlet code.
package pack;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import pack.employbean;
import java.util.Enumeration;
import java.util.Vector;
import pack.*;
public class ser1 extends HttpServlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
employbean ebean = new employbean();
Vector v = ebean.getResult();
Enumeration en = v.elements();
while(en.hasMoreElements())
out.println("employee id= "+ en.nextElement());
// out.println("employid"+employid);
catch(Exception m)
out.println(m);
out.close();
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
try
processRequest(request,response);
catch(Exception e)
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
try
processRequest(request,response);
catch(Exception e)
/** Returns a short description of the servlet.
public String getServletInfo()
return "Short description";
Send me the output

Similar Messages

  • Want to display from database but javaclass not returning values to servlet

    I am trying to view values stored in database using jsp, servlets and java class. Jsp is calling servlet and servlet calls java class file. and javaclass file retrieves data from database and sends it back to servlet. But my problem is javaclass file doesnt return the value to servlet and print. Here is my code
    This is the javaclass file.
    package pack;
    import java.util.*;
    import java.sql.Driver.*;
    import java.sql.Connection.*;
    import java.sql.*;
    import java.sql.DriverManager.*;
    import java.sql.SQLException.*;
    import java.io.*;
    import java.io.Serializable;
    import java.util.Vector;
    import pack.ser1;
    /* Control is got from the servlet file */
    public class employbean implements Serializable
      public Vector result;
      public Vector getResult() throws ClassNotFoundException, InstantiationException, IllegalAccessException
                /* Connection is established to retrieve data from the database */
                Vector v = new Vector();
                ResultSet rs = null;
                PreparedStatement st = null;
                try
                 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                 Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?user=user&password=password");
                  st = connection.prepareStatement("Select * from samp");
                  rs = st.executeQuery();
                  while(rs.next())
                      v.addElement(rs.getString("empid"));
                  st.close();
                  connection.close();
                 catch(SQLException esql)
                      esql.printStackTrace();
                  this.result = v;
                 /* Control is sent back to the servlet */
                 return result;
    }Here is the servlet code.
    package pack;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import pack.employbean;
    import java.util.Enumeration;
    import java.util.Vector;
    import pack.*;
    public class ser1 extends HttpServlet
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try
              employbean ebean = new employbean();
              Vector v = ebean.getResult();
              Enumeration en = v.elements();
              while(en.hasMoreElements())
                out.println("employee id= "+ en.nextElement());
              out.println("employid"+employid);
             catch(Exception m)
               out.println(m);
             out.close();
            // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        /** Returns a short description of the servlet.
        public String getServletInfo()
            return "Short description";
    }Please help me with my code as where i might have gone wrong and help me rectifying the errors.
    I also would like to know if this is MVC pattern.
    Thanks in Advance

    I am trying to view values stored in database using jsp, servlets and java class. Jsp is calling servlet and servlet calls java class file. and javaclass file retrieves data from database and sends it back to servlet. But my problem is javaclass file doesnt return the value to servlet and print. Here is my code
    This is the javaclass file.
    package pack;
    import java.util.*;
    import java.sql.Driver.*;
    import java.sql.Connection.*;
    import java.sql.*;
    import java.sql.DriverManager.*;
    import java.sql.SQLException.*;
    import java.io.*;
    import java.io.Serializable;
    import java.util.Vector;
    import pack.ser1;
    /* Control is got from the servlet file */
    public class employbean implements Serializable
      public Vector result;
      public Vector getResult() throws ClassNotFoundException, InstantiationException, IllegalAccessException
                /* Connection is established to retrieve data from the database */
                Vector v = new Vector();
                ResultSet rs = null;
                PreparedStatement st = null;
                try
                 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                 Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?user=user&password=password");
                  st = connection.prepareStatement("Select * from samp");
                  rs = st.executeQuery();
                  while(rs.next())
                      v.addElement(rs.getString("empid"));
                  st.close();
                  connection.close();
                 catch(SQLException esql)
                      esql.printStackTrace();
                  this.result = v;
                 /* Control is sent back to the servlet */
                 return result;
    }Here is the servlet code.
    package pack;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import pack.employbean;
    import java.util.Enumeration;
    import java.util.Vector;
    import pack.*;
    public class ser1 extends HttpServlet
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try
              employbean ebean = new employbean();
              Vector v = ebean.getResult();
              Enumeration en = v.elements();
              while(en.hasMoreElements())
                out.println("employee id= "+ en.nextElement());
              out.println("employid"+employid);
             catch(Exception m)
               out.println(m);
             out.close();
            // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        /** Returns a short description of the servlet.
        public String getServletInfo()
            return "Short description";
    }Please help me with my code as where i might have gone wrong and help me rectifying the errors.
    I also would like to know if this is MVC pattern.
    Thanks in Advance

  • My hard drive went bad and I lost a lot of purchased items from the iTunes store. I want to re-download them but can not. They still show up on my purchased items. How do I solve this?

    My hard drive went bad and I lost a lot of purchased items from the iTunes store. I want to re-download them but can not. They still show up on my purchased items. How do I solve this?

    Update to iTunes 10.3.1
    After you have finished, you can re download your iTunes purchases without having to re purchase.
    iTunes 10.3.1
    " Download Previous Purchases. Download your past music purchases again at no additional cost. Your purchases are available in the iTunes Store on your Mac or in the iTunes app on your iPhone, iPad, or iPod touch. Previous purchases may be unavailable if they are no longer on the iTunes Store."
    "Available on iTunes in the U.S. and Canada only. Title availability is subject to change."
    From here.  http://www.apple.com/itunes/

  • HT4191 I deleted notes on my mac but did not want them deleted from iPhone but after synching they are all done. Can I get them back?

    I deleted notes on my mac but did not want them deleted from iPhone but after synching they are all done. Can I get them back?

    Deleting on one device does not affect another device.
    You can delete the App's on the iPhone and nothing will happen to the ones on the iPad.
    1.  You don't need to.
    2.  Settings->Cellular->"Use Cellular Data For" will show the data usage for each App since the last statistics reset
    3.  Settings->General->Background App Refresh Will show which Apps are allowed to get data in the background
    4.  It restricts it to Wifi.  If the App requires internet access and Data is turned off, it will have to wait until the device is connected to a wifi network.
    5.  Nope, You just use up battery since the BT radio will continuously look for nearby BT devices.
    6.  The Personal Hotspot uses your cellular internet connection from your phone or other cellular device; whether you consider that secure or not I cannot say.  It also depends on what you are doing while connected to the Hotel's wifi. I would not do online banking while on vacation though.

  • Hi i have bought an iphone from dubai but its not working in pakistan

    hi i have bought an iphone from dubai but its not working in pakistan its not syncing my phone displaying mesage that invalid sim card. I have changed sim card but its not working. Can you please help to to make it work. Its a pay as u go phone.

    Fais1 wrote:
    I have called to the shop where i bought the phone they told me that phone is not locked. I have tried so many times but phone is not working vth any sim a part from the one i have bought from dubai. Pls let me know how to check that phone is locked or not. Thanks
    And, of course, they would NEVER lie to you after they already have your money...

  • TS3274 How can I connect tv to ipad?  Want it to use netflex but will not connect using USB cable.

    How can I connect tv to ipad?  Want it to use netflex but will not connect using USB cable.

    http://store.apple.com/us/browse/home/shop_ipad/ipad_accessories/cables_docks
    You should find a solution here

  • Some movie rentals i can transfer from ipad but most not! Whats the problem? They are all SD.

    Some movie rentals i can transfer from ipad but most not! Whats the problem? They are all SD. Some are watched others not. It just seems to be a fluke sometimes that they show up in the rented movies when i sync. And bought movies I always have to manually transfer to my computer!

    How did you rent them ? From http://support.apple.com/kb/HT1657 :
    If you download a rented movie on your computer: You can transfer it to a device such as your Apple TV (1st generation), iPhone, iPad, or iPod if it’s a standard-definition film (movies in HD can only be watched on your computer, iPad, iPhone 4 or later, iPod touch (4th generation or later), or Apple TV). Once you move the movie from your computer to a device, the movie will disappear from your computer's iTunes library. You can move the movie between devices as many times as you wish during the rental period, but the movie can only exist on one device at a time.
    If you download a rented movie on your iPhone 4 or later, iPad, iPod touch (4th generation or later), or Apple TV: It is not transferable to any other device or computer.

  • Hello .. i own icloud account but i have a problem, because i need to change my security questions, and i want to reset from email, But rescue email is diffrent from my alternat email, because i can't use my credit

    hello .. i own i cloud account but i have a problem, because i need to change my security questions, and i want to reset from email, But rescue email is different from my alternate email, because it's my 1st usage for my credit and i can't accomplish it without using the secret question ..please help

    Hello, yehyakov.  
    Thank you for visiting Apple Support Communities.  
    I understand that you want to reset your security questions for your iCloud account.  Here is an article that will provide multiple options to help you with this.  
    If you forgot the answers to your Apple ID security questions
    http://support.apple.com/en-us/HT201485
    Cheers, 
    Jason H.  

  • I want to split an event but do not have a split icon. Help!

    New Mac user. I want to split an event but do not see the split icon.

    in the help window type in "split" - it will show you the command (event menu ==> split event)
    learn to use HELP - it is extremely "Helpful"
    LN

  • HT1766 My iPad hasn't been backed up and it's displaying the msg but will not let me get rid if the msg so that I can get it backed up. How do I get through this

    My iPad hasn't been backed up and it's displaying the msg but will not let me get rid if the msg so that I can get it backed up. How do I get through this

    Try this.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up

  • At you tube display video window but did not appear play, pause and sound bottons

    at you tube display video window but did not appear play, pause and sound buttons, last night i watch the video at you tube perfectly.

    It looks like a driver related issue specifically the video card driver. I suggest that you scan your computer with RadarSync so that you will know which drivers need some updating. Once you some results, you can either Google the updates or go to the HP's support website to get the latest updates or you can use RadarSync to update automatically. I hope this helps! David

  • The LOV modal window could not return value to the base page

    when practicing the "create1" task in tutorial, met an issue.
    when create an employee, manageName is a messageLovInput and managerID is a messageTextInput.
    The issue is the LOV modal window could not return value to the mangerName, but can return to managerID .
    If I remove the data boud porperties of the managerName (the bc4j porperties of view name-EmpFullVO and view attribute-MgrName), the lov works fine.
    What is the reason?

    James I would suggest to read the LOV topic in OAF developers' guide. Lov mappings are responsible for bringing pop up values to base page in LOV.
    --Mukul                                                                                                                                                                                                                                                                                                                                                   

  • My iTunes got deleted off a (no longer working) computer. Is there a way I can transfer all content from my iPhone onto iTunes on a new computer? I want to update my phone, but do not want to lose any music off it when syncing it.

    My iTunes got deleted off a (no longer working) computer. I have lost all music & data that was on this original itunes. Is there a way I can transfer all content from my iPhone (music & photos) onto iTunes on a new computer? I want to update my iphone (3GS), but do not want to lose any music off it when syncing it. Help please!!

    By design, the iphone will sync itunes content with one computer at a time. Any attempt to sync such content with a second computer will result in ALL itunes content being first erased from your phone & then replaced with the content from the second computer. This is a design feature and cannot be overridden. Because you are using a new computer, your phone will see this computer as a "new" computer. The itunes content sync is one way: computer to phone. If you have photos that were synced to your phone or music ripped on your own that were not backed up, you will first have to extract them from your phone using third party software, before you do anything else, as Apple makes no provision to do so:
    http://www.wideanglesoftware.com/touchcopy/index.php
    Once you've done that, do the following in the order specified:
    1. Disable auto sync when an iPod/iPhone is connected under iTunes>Preferences(under the edit menu if using Windows)>Devices in itunes.
    2. Make sure you have one contact & one event in the supported applications(Address Book & iCal or Outlook, Windows Address Book) on your computer. These entries can be fake, doesn't matter, the important point is that these programs not be empty.
    3. Connect your phone, iTunes running, DO NOT SYNC at this point.
    4. Store>Authorize this computer.
    5. File>Transfer Purchases(To make sure all purchased content on your phone will be in your itunes library).
    6. Right click in the device pane & select reset warnings.
    7. Right click again and select backup.
    8. Right click again & select restore from backup, select the backup you just made. When prompted to create another backup, decline.
    9. This MUST be followed by a sync to restore your itunes content, which you select from the various tabs, You'll get a popup regarding your contacts & calendars asking to merge or replace, select merge.
    You should be good to go.

  • I want to use a dynamic schema name in the from clause but its not working.

    DECLARE
         vblQueryName VARCHAR2(20);
         vblSchemaName VARCHAR2(20);
    BEGIN
         SELECT CurrentSchemaName INTO vblSchemaName FROM HR_989_SCHEMA;
         vblQueryName:='060_525_020';
         INSERT /*+ APPEND(HP_ELIGIBILITIES,4) */ INTO HP_ELIGIBILITIES
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         SELECT /*+ PARALLEL(a,4) */
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         FROM
         bold     vblSchemaName.HP_ELIGIBILITIES a
         WHERE
              UPPER(LVL2ID) = 'XX' ;
         COMMIT;
    DBMS_OUTPUT.PUT_LINE( 'Query Executed: ' || vblqueryName);
    INSERT INTO HP_QUERYEXECLOG(QueryName) VALUES(vblQueryName);
    EXCEPTION WHEN NO_DATA_FOUND THEN NULL;
    END;
    I want to create a rules table so that the schema name in front of the table name in the from clause can be controlled by a separate table that is maintained but its not working . Help and your valuable inputs needed for this issue

    I want to use a dynamic schema name in the from clauseyou can alternatively set the current schema as e.g. in:
    declare
       vblqueryname    varchar2 (20);
       vblschemaname   varchar2 (20);
    begin
       select currentschemaname into vblschemaname from hr_989_schema;
       vblqueryname := '060_525_020';
       execute immediate 'alter session set current_schema=' || vblschemaname;
       insert /*+ APPEND(HP_ELIGIBILITIES,4) */
             into hp_eligibilities (lvl1id,
                                    lvl1desc,
                                    lvl2id,
                                    lvl2desc,
                                    lvl3id,
                                    lvl3desc,
                                    lvl4id,
                                    lvl4desc
          select /*+ PARALLEL(a,4) */
                lvl1id,
                 lvl1desc,
                 lvl2id,
                 lvl2desc,
                 lvl3id,
                 lvl3desc,
                 lvl4id,
                 lvl4desc
            from hp_eligibilities a
           where upper (lvl2id) = 'XX';
       commit;
       dbms_output.put_line ('Query Executed: ' || vblqueryname);
       insert into hp_queryexeclog (queryname)
       values (vblqueryname);
    exception
       when no_data_found
       then
          null;
    end;

  • I am purchace ipad 2 3g from dubai but facetime not installed

    i am purchase ipad 2 3g from dubai but accidently i update ipad2 in itune for ios 4.3.5
    after installed face time not installed

    It can't be unblocked, it is blocked by the serial number. If you want to do FaceTime type calls then, if it's available in your country, you could download the Skype For iPad app from the app store.

Maybe you are looking for