Best Practive to resturn Resultset to a JSP page

I'm writing a class to return a resultSet to use in a JSP page or at least i think thats what i want to do. Whats the best practice to return that resultset.....As the class is written below, when i try to iterate through the resultset in the jsp page i get a NullPointerException which i understand because i closed the connection before returning....If i take out all the code in the finally section i can iterate through the data no problem....but thats not good to leave connections open.......instead of returning a resultset should i return some other type such as an Array with all the data. How should i return the data?
======================================================================
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest{
String foo = "Not Connected";
String bar = "Not";
public ResultSet getUser(){
Connection conn = null;
Statement stmt = null; //Or preparedStatement if needed
ResultSet rs = null;
try{
Context ctx = new InitialContext();
if(ctx == null)
throw new Exception("Boom - No Context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Show");
if(ds != null){
conn = ds.getConnection();
if(conn != null){
foo = "Got Connection " + conn.toString();
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM user");
if(rs.next()){
foo=rs.getString("login");
bar=rs.getString("password");
}catch(Exception e){
e.printStackTrace();
}finally{
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool.
if(rs != null){
try{
rs.close();
}catch(SQLException e){;}
rs=null;
if(stmt != null){
try{stmt.close();}catch(SQLException e){;}
stmt=null;
if(conn != null){
try{conn.close();}catch(SQLException e){;}
conn=null;
return rs;
public String getFoo(){return foo;}
public String getBar(){return bar;}

Yes, when you close your connection all data in your result set is lost, and yes its not a good idea to keep connections open. Its also not a good idea to pass results around. What you should do is store the data in some type of collection object and pass that to your jsp.
for exmaple if you select data from a table that stores names of people, e.g. two columns first_name and last_name, then create a class called People with two private string members to hold the first and last names. loop through your result set and build a People object for each row of data. when your done close the result set (and the connection if you want). store all your People objects is a collection (vector, array, whatever). pass the vector to your jsp for display.
-S-

Similar Messages

  • What is the best way to output query result in jsp page?

    I have several pages with 2-3 queries on each one.
    My jsp pages call a class that I've created, the class will create a connection with the db, execute the query and returns the ResultSet to the jsp page. Then I iterate the RS on the jsp page.
    Is there a better way of sending the data back to the jsp? I was thinking of .xml.

    Send it back as a java.util.List, or some other Collection. Then iterate through the collection. My preference is to make a Bean of the date that represents a Row on the ResultSet and put those in the List. Then when we get to the JSP, iterate the List to get the beans, and call get methods to get the values...
      /* In a method that traverses ResultSet and fills a List of  beans... */
      List data = new ArrayList();
      while(results.next())
        MyBean mb = new MyBean();
        mb.setProperty1(rs.getString(1)); //But give properties good names
        mb.setProperty2(rs.getString(2)); //Not 'Property1 and Property2
        data.add(mb);
      return data;If you are using JSTL you can do something like this:
      <c:set var="myBeans" value="${theDbObject.results}"/> //Assuming the above method was called 'getResults()'
      <table>
      <c:forEach var="mb" items="${myBeans}">
        <tr><td>${mb.property1}</td><td>${mb.property2}</td>...</tr>
      </c:forEach>
      </table>

  • Best practice of getting request parameters in JSP page

    int period_Id = 0;
    try
    period_Id = Integer.parseInt(request.getParameter("period_id"));
    catch(Exception e)
      period_Id = 0;
    }This is the normal way we use to get parameters from previous page.
    But I am not sure if it is thebest practice.
    Please respond if anyone knows a better way.
    Regards

    Using java code in a JSP is a horrible practice. There are far better ways to write JSP's nowadays in the form of custom tags, JSTL and possibly JSF. Combined with servlets this will make your code clean, reusable and maintainable.
    However if you insist and using scriptlets, I'd say create your own request bean that wraps around the HttpServletRequest and write methods getParameterInt(), getParameterDouble(), etc. Such a method could look like this:
    public int getParameterInt(String name, int default)
    String paramstr = request.getParameter(name);
    if(paramstr == null || paramstr.length() == 0){
      return default;
    try{
       return Integer.parseInt(paramstr);
    } catch(Exception e) {
      return default;
    }With such a bean you never have to do that exception catching yourself again: you can just pass the parameter name and a default value that will be returned if the parameter does not exist or is not a valid integer.

  • Suggest me the best practise for accesing database by JSP page

    Hi,
    Can you please suggest me the best practises to connect to database through JSP page.
    I am using the Struts-Portlet environment. And I have to display some contents from the database to the jsp page(view.jsp).
    Please suggest.
    Saurabh.

    If you know how to use struts and portlets, you wouldn't be asking this question. I suggest looking into the Model-View Controller pattern to get an idea how to set up a web application, then think about how to do it in a portlet environment.

  • How to use one ResultSet many times in a jsp page ?

    Hi all,
    I have .jsp page and I have used it to get data from DB and display them to users. So I have to get data from DB in number of places in this particular jsp.
    I thought that it is better to have one ResultSet for entire page and once it is done its job, the ResultSet will be closed and I can use it again and again like this.
    Resultset rs = new ResultSet();
    try{
        //My operations
    }catch(Exception ex){
       //Handle Exceptions
    }finally{
       rs.close();
    }After above code snippet I can use same ResultSet again below the page.
    I just want to know this,
    1. is this a good coding practice?
    2. Should i put rs = null; within finally clause?
    any help will be appreciated
    thank in advance,
    Dilan.

    Ok, Finally I switched my coding to use DAO and DTO, and I learned it through internet.
    I removed all of data access codes from my jsp file(lets say 'functions.jsp'). I then created one interface and two clasess.
    here is my DAO interface.
    public interface UserFunctionsDAO{
        public List<UserFunctionsDTO> selectUserList();
    }here is DTO class
    public class UserFunctionsDTO{
        private String category = "";
        private String sub_category = "";
        private int cat_id = 0;
        private int sub_cat_id = 0;
        public UserFunctionsDTO(){}
        public UserFunctionsDTO(String category, String sub_category, int cat_id, int sub_cat_id){
            this.category = category;
            this.sub_category = sub_category;
            this.cat_id = cat_id;
            this.sub_cat_id = sub_cat_id;
        //Setters and getters will go here.
    }my concrete data access class is like this.
    public class UserFunctionsDataAccess implements UserFunctionsDAO{
        MyDB dbObject = null;
       private static final String SQL_GET_DISTINCT_CAT= "SELECT DISTINCT cat FROM cat_table";
       public List<UserFunctionsDTO> selectUserList(){
           dbObject = new MyDB();
           dbObject.sqlSelect(SQL_GET_DISTINCT_CAT);
           ResultSet rs = dbObject.getResultSet();
           ArrayList list = new ArrayList();
           while(rs.next()){
               list.add(new UserFunctionsDTO(rs.getString('category'), .......................));
           return list;     
    }I think now im following good coding practices, but I have one problem.
    1. How do I retrieve this userlist from my jsp page?
    2. Should I include UserFunctionsDTO in my jsp page as a bean?
    3. If I include it, how can I get the list from it?
    thanks in advance,
    Dilan.

  • Displaying Same ResultSet Twice In A JSP Page

    I have a table that lists team names in my database. I'm trying to create a page with 2 dropdown boxes where each lists all the teams in the league (in other words, the data read in from the table). I got the first dropdown box to populate w/ this info. My question is about the 2nd dropdown box:
    Since I already have the ResultSet from the 1st dropdown, I would think it would be a waste to make another DB-read to fill in the 2nd dropdown. However, when I tried to call ResultSet.first() it gave me the error that it was TYPE_FORWARD_ONLY. I checked the documentation for Connection and it looks like there are some overloaded methods for createStatement. However, the API documentation (see below) is pretty confusing. I'm not sure what "resultSetConcurrency" or "resultSetHoldability" I need if I just want to read the same data twice. Can someone point me in the right direction?
    Statement createStatement(int resultSetType, int resultSetConcurrency)
    Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
    Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
    Creates a Statement object that will generate ResultSet objects with the given type, concurrency, and holdability.

    I am also having a very similar problem.
    I am having a table having 20 fileds.some of them r to be displayed in one table
    others in some other table.
    for this i am using a bean which returns a resultset which is then used in jsp page
    for display.But i have to call the javabean method twice which fires the query & returns the resultset.
    I cannot store so many fileds with so many rows of values in list of objects also i do not want to
    fire query twice.
    rs.movefirst() does not work, so what should i do.

  • Database query ResultSet from servlet to JSP page

              Hi there,
              I have an Access 2000 database. I am running Apache and Tomcat on Windows Me.
              I would like to know if it is possible for me to use a Servlet to search the
              database (I know this bit is possible!), but then I would like the servlet to
              forward to a jsp page which will then display the ResultSet that the servlet has
              retrieved, i.e. when forwarding from a servlet to a jsp, is it possible for the
              jsp page to have access to the servlet's data? I know that it gets access to
              the response and request objects, but what about a ResultSet?
              Sorry it this sounds a little silly - i am a bit of a newbie.
              Thanks in advance for your help,
              SJ
              

    HttpServletRequest.setAttribute let's you share data for a particular
              request. When you call forward you can store the resultset in the request.
              Make sure your JSP does close the result set though, because what you are
              trying to do doesn't sound good :)
              If you want to share data across the session, take a look at the HttpSession
              object.
              read through the servlet specification, it is fairly easy to read and will
              give you all the info you need
              Filip
              ~
              Namaste - I bow to the divine in you
              ~
              Filip Hanik
              Software Architect
              [email protected]
              www.filip.net
              "SJ" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hi there,
              >
              > I have an Access 2000 database. I am running Apache and Tomcat on Windows
              Me.
              > I would like to know if it is possible for me to use a Servlet to search
              the
              > database (I know this bit is possible!), but then I would like the servlet
              to
              > forward to a jsp page which will then display the ResultSet that the
              servlet has
              > retrieved, i.e. when forwarding from a servlet to a jsp, is it possible
              for the
              > jsp page to have access to the servlet's data? I know that it gets access
              to
              > the response and request objects, but what about a ResultSet?
              >
              > Sorry it this sounds a little silly - i am a bit of a newbie.
              >
              > Thanks in advance for your help,
              >
              > SJ
              

  • How to display my ResultSet in a JSP??

    First off, I'm new to Java programming.
    Here's my problem. I have a set of users in my database. I'd like to retrieve all the user ID's (these are integers) from my User-table and display them in a JSP. Now, I realize that my coding below isn't very efficient as it's not exactly a MVC approach. I'm just trying to learn what a ResultSet is and how to manipulate it.
    I send my ResultSet to a JSP by "request.setAttribute("usersId", usersId);" but then I'm not sure what to do in my JSP to actually display my User ID's.
    My code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    try {
    String dbURL = "jdbc:mysql://localhost:3306/heading360";
    String username = "root";
    String password = "";
    Connection connection = (Connection) DriverManager.getConnection(
    dbURL, username, password);
    Statement statement = (Statement) connection.createStatement();
    ResultSet userId = (ResultSet) statement.executeQuery("SELECT UserId FROM User");
    request.setAttribute("userId", userId);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/testUserId.jsp");
    dispatcher.forward(request, response);
    catch (SQLException e) {
    for (Throwable t : e)
    t.printStackTrace();
    }

    flukyspore wrote:
    OK thanks for the quick response.
    I am using using JSP EL to write my JSP's. Still learning JSTL.Bad idea. Learn JSTL.
    I understand everything you're saying, except I can't seem to find the exact approach to load my ResultSet into an object or collection. Could you give me an example of how to do that. My ResultSet is one column of User ID's, they are integers. Something like this:
    private static final String FIND_USER_ID_SQL = "SELECT USER_ID FROM USERS";
    private Connection connection;
    public List<Integer> findUserIds()
        List<Integet> userIds = new ArrayList<Integer>();
        Statement stmt = null;
        ResultSet rs = null;
        try
            stmt = connection.createStatement(sql);
            rs = stmt.executeQuery();
            while (rs.next())
                userIds.add(rs.getInt("USER_ID"));
        catch (SQLException e)
            e.printStackTrace();
        finally
            close(rs);
            close(stmt);
        return userIds;
    }Fill in the blanks.
    %

  • The best  way of carrying the search string across different jsp pages?

    I heard about transfer object. What about carrying object with session for different pages.
    Please suggest me the best approach to
    carry the search string across different jsp pages?
    thanks
    vijendra

    I doubt its possible even with a fancy HTML widget, although the last iBA update now allows links to other books.

  • Timed out issue in jsp page!

    Dears,
    It is really amazing for me to see this issue in my application which I deployed in Oracle Application Server 10g r2.
    I am using JDeveloper 10g to create jsp pages.
    On one jsp page i am displaying 15 html tables for a report.
    All tables have 1 query to get records from oracle 10g database.
    Am opening one connection and than one by one running queries just before each table and rendering data through ResultSet
    (which is scrollable).
    If I test this page from JDeveloper, it is displaying fine.
    But when I deploy this page in Oracle Application Server 10g,
    and create a portlet and show this jsp page in portlet and open this page,
    this page most of the time giving 'TIMED OUT', and a few times displaying report properly.
    I tried PreparedStatement to run multiple queries for Oracle DB, but couldn't make it successfully.
    BTW,
    I checked my OAS log, it shows following error:
    09/03/16 18:39:08 hrwfapp: [instance=(null), id=(null)] ERROR: Request has exceeded its warning timeout Time[elapsed=61046ms.
    Warning timeout=20000ms.] Request[id=5003532663665,3 providerId=493501 portletId=117 portletName=AttritionReports
    portletInstance=35555_ATTRITIONREPORTS_493501 user=PUBLIC] Thread[ name=AJPRequestHandler-ApplicationServerThread-6
    priority=5 alive=true interrupted=false groupName=ApplicationServerThreadGroup]
    Please help me in this regard, what should I do to avoid Timed out issue.
    Best Regards

    Hi,
    if this occurs only in combination with portlets then I would try the Oracle Portal forum for help or use customer support to help you analyzing the issue
    Frank

  • How to get the value in one JSP page to another?

    Hi,
    I have problems in passing the value around in JSP. I have two JSP pages as below:
    test1.jsp
    I try to get the vaule from my textbox by using:
    String strUser = request.getParameter ("strUserName");
    Then i print out by using: out.print(strUser); then i can get the value and put on my page (For example, i get ABC on my page).
    test2.jsp
    Next, i want to get the value from strUser (which mean that the one i already display on page in test1.jsp, ABC) to insert into my table by using INSERT INTO statement. Then i try by using
    String strUser1 = request.getParameter ("strUser");
    Is it possbile for me to do that? I cannot get anything to insert into my table. Then i tried out.print(strUser1); then i found that i get NULL value.
    Could you please give me some guidance?
    Thanks you very much for any advise you may give me.
    Kimsan

    Hi,
    Thank you very much for your help. It's working fine if i just get a one value to another page, however, i have problem while i pass the value in my loop to another page because i always get the last record. I try with the following code:
    logged_page.jsp
    <html>
    <head>
    <title>Welcome to the online Auction...</title></head>
    <body>
    <%@ page language ="java" import = "java.io.*, java.lang.*, java.sql.*" %>
    <% try
         String strUsername = request.getParameter("username");
         session.setAttribute("myUserName", strUsername);     
         String strPassword = request.getParameter("password");
         Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection myConn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb");
         String strSQL = "SELECT [UserName], [Password] FROM tblUserDetails where [UserName] = ? and [Password] = ?";
         PreparedStatement statement = myConn.prepareStatement(strSQL);
         statement.setString(1, strUsername);
         statement.setString(2, strPassword);
         ResultSet myResult = statement.executeQuery();
         if(myResult.next())
         //out.println("Login Succesful! A record with the given user name and password exists");
         out.print("<center><h1>");
         out.print("Welcome  ");
         out.print(strUsername);
         out.print("</h1></center>");
         out.print("<center>");
         out.print("<BR><BR>");
         out.print("<font font face = Viner Hand ITC size= 5>Products on sales</font>");
         out.print("<BR><BR>");
         Statement myStatement = myConn.createStatement ();
         ResultSet myResult1 = myStatement.executeQuery("SELECT * FROM tblProduct");
         ResultSetMetaData myResultSet = myResult1.getMetaData();
         out.println("<font face=Tahoma>");
         out.print("<table border=1 CELLSPACING=0>");
         out.print("<TR>");
         out.print("<TD width = 200> Item Title");out.print("</TD>");
         out.print("<TD width = 200> Description");out.print("</TD>");
         out.print("<TD width = 200> Current bid");out.print("</TD>");
         out.print("<TD width = 200> Available Time");out.print("</TD>");
         out.print("<TD width = 200> Place Bid");out.print("</TD>");
         out.print("</TR>");
         out.print("</table>");
         while(myResult1.next())
              String strProName = myResult1.getString(1);
              session.setAttribute("myProName", strProName);          
              out.print("<table border=1 CELLSPACING=0>");
              out.print("<TR>");
              out.print("<TD width = 200>");
              out.println(strProName);
              out.print("</TD>");
              out.print("<TD width = 200>");
              out.println(myResult1.getString(3));
              out.print("</TD>");
              out.print("<TD width = 200>");
              out.println(myResult1.getString(2));
              out.print("</TD>");
              out.print("<TD width = 200>");
              out.println(myResult1.getString(4));
         out.print("</TD>");
         out.print("<TD>");
              out.print("<form action=bid_page.jsp method=post>");
              out.print("<input type=text name=place_bid>");
              out.print("<input type=submit name=okfunc value=Bid>");
              out.print("</TD>");
              out.print("</form>");
              out.print("</TR>");
              out.print("</table>");
              out.println("</font>");
              out.print("</center>");          
         else
              out.print("<center>");
              out.print("Sorry ");
              out.print("<font color = RED size = 5>");
              out.print(strUsername);
              out.print("</font>");
              out.print(" could not be found.");
              out.print("</center>");
         myResult.close();
         statement.close();
         myConn.close();
         catch(SQLException e)
         out.println(e);
    %>
    </body>
    </html>
    bid_page.jsp
    <HTML>
    <HEAD>
    <TITLE>Welcome to the online Auction...</TITLE>
    </HEAD>
    <BODY>
    <%@ page language ="java" import = "java.io.*" import = "java.lang.*" import = "java.sql.*" %>
    <% try
         String thisUserName = (String) session.getAttribute("myUserName");
         String thisProName = (String) session.getAttribute("myProName");
              Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection myConn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb");
         PreparedStatement myStatement = myConn.prepareStatement("INSERT INTO tblHistory VALUES ('"+thisUserName+"', '"+thisProName+"', '"+request.getParameter("place_bid")+"')");
              myStatement.executeUpdate();
              myConn.commit();
              myStatement.close();
              myConn.close();
              catch(Exception e){}
    %>
    </BODY>
    </HTML>
    When i click on the BID button in the logged_page.jsp then i always get the last record and save into my table and that is not what i want to. i want to get the result on the same row as the BID button that just click and save to my table.
    Could you please advise?
    Thanks you very much for your time and any consideration you may give me.
    Best Regard,
    Kimsan

  • Display image on jsp page

    I have to display image on jsp page with some text output. This image is already saved at a location parallel to web-inf and is generated dynamically using a servlet. I have used img tag html to display the image. Other outputs are taking their values from database.
    First problem is that image will be taking time to display in comparision of other outouts from database. I have to refresh the page to get imageon my page.
    Second is that if I save image in a folder parallel to web-inf in my project then it will not be displaying the image.
    Can I use any jsp functionality to display image with other outputs from database. I have used "*include*". but it shows only that image and other outputs.

    Best way is to use a servlet for this.
    <img src="path/to/imageservlet?id=someidentifier">
    <!-- or -->
    <img src="path/to/imageservlet/someidentifier">In the servlet's doGet() just write code which gets an InputStream of the image (either directly generated, or just read from the local disk file system, if necessary with help of ServletContext#getRealPath(), or even from the DB by ResultSet#getBinaryStream()) and writes it to the OutputStream of the response. That's basically all. Don't forget to buffer the streams properly to speedup performance and to save memory.
    You can find here a basic example: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • How am i supposed to prevent sm from pasting code in my JSP page?

    Hello,
    as i was testing my JSP page i noticed that when sm places code in an input box , it seems that the page is affected by that.
    Well i have a very simple form like:
    <form  style="text-align:left" method="POST" name="edit" action="Edit" >
    <input type="text" name="year" size="5" maxlength ="50" value="<%= convertdate.ReturnYear((resultset.getString(19)) %>">
    <input type="submit" name="Submit" value="Store Data" >
    </form>i noticed that when i was placing code in the button year of the form like:
    out.println("<HTML><HEAD><TITLE> " + "Error in PAGE BLAH BLAH BLAH" + " </TITLE></HEAD><BODY>");my website was affected by that and some pages looked different and couldn't display data from the database, although the data existed in the db.
    What am i supposed to do? How am i supposed to prevent a user from inserting code in inputs of a form?
    Also, sometimes when i was pasting code, some SQL exceptions appeared saying : Data too long for field etc.
    The weird was that the data was in the limit. I'm very worried about this problem because the sql exceptions show the names of my tables and i think
    that this is dangerous for malicious attacks in the website.
    Thanks, in advance!
    Edited by: g_p_java on Sep 5, 2009 5:09 PM
    Edited by: g_p_java on Sep 5, 2009 5:14 PM
    Edited by: g_p_java on Sep 5, 2009 5:15 PM

    smogura.eu wrote:
    All notices are important & how to say... you can place Java code in JSP, but in commercial job you will need to find new job.
    Well i'm not actually working somewhere, i'm student and i have to make this project.
    It's the first time I use JSP, servlets etc, so that's why i find a difficulty in using them.
    Why your pages are messed? If you put HTML code in db, rendered page is like
    ..="50" value="<HTML><HEAD...{code}
    this will prevent browser to render page properly. Well i was actually pasting some data in order to check if the data is too long for the field and afterwards the page changed and many fields disappeared...
    There are two ways to prevent inserting code, in your JSP, and you need use it, as no separating view logic, data acquisition from page will not prevent this error
    1. You need disallow user entering ", <, ' etc...., best way by validating input on server side, by this will prevent user from entering all texts, or
    2. You need replace all HTML special char with their HTML codes when rendering, the simplest way
    convertdate.ReturnYear((resultset.getString(19)).replace("\"", "&#34'").replace(...).replace(...)
    {code}
    You must use this in back logic.May you please elaborate on that, you mention that i shall replace the year with "&#34'",
    What is that "&#34'"?
    and why do you use 3 "replaces"?
    About prepared statements.
    Preparation will not only prevent you from SQL injections, but can speed up application, if your driver uses statement caching.
    Why after creating prepared statement, you then create normal statement, in your example code?I hadn't noticed that, thanks.I 'll change them. But Statement is less secure than PrepareStatement?
    Thanks, in advance!

  • [b]Error during JSP page processing[/b]

    hi , i'm mech.
    i have some probs with jsp. i am trying to connect jsp page with database and printing the data on the browser page. i have created DSN mm using microsoft odbc for oracle and oracle9i's driver oracle in orahome90 but it is giving yet . i have this coding and error.
    ------------------------jsp code--------------------------
    package pagecompile.jsp;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    import java.io.FileInputStream;
    import java.io.ObjectInputStream;
    import java.util.Vector;
    import com.sun.server.http.pagecompile.jsp.runtime.*;
    import java.beans.*;
    import com.sun.server.http.pagecompile.jsp.JspException;
    import java.sql.*;
    public class _Connect extends HttpJspBase {
    static char[][] jspxhtml_data = null;
    public _Connect( ) {
    private static boolean jspxinited = false;
    public final void jspxinit() throws JspException {
    ObjectInputStream oin = null;
    int numStrings = 0;
    try {
    FileInputStream fin = new FileInputStream("E:\\JavaWebServer2.0\\tmpdir\\default\\pagecompile\\jsp\\pagecompile.jspConnect.dat");
    oin = new ObjectInputStream(fin);
    jspxhtml_data = (char[][]) oin.readObject();
    } catch (Exception ex) {
    throw new JspException("Unable to open data file");
    } finally {
    if (oin != null)
    try { oin.close(); } catch (IOException ignore) { }
    public void _jspService(HttpServletRequest request, HttpServletResponse  response)
    throws IOException, ServletException {
    boolean jspxcleared_due_to_forward = false;
    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    String _value = null;
    try {
    if (_jspx_inited == false) {
    jspxinit();
    jspxinited = true;
    _jspxFactory = JspFactory.getDefaultFactory();
    response.setContentType("text/html");
    pageContext = _jspxFactory.getPageContext(this, request, response,
                   "", true, 8192, true);
    application = pageContext.getServletContext();
    config = pageContext.getServletConfig();
    session = pageContext.getSession();
    out = pageContext.getOut();
    out.print(_jspx_html_data[0]);
    out.print(_jspx_html_data[1]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(14,2);to=(28,2)]
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection myconn=DriverManager.getConnection("Jdbc:Odbc:mm","madhulika","madhulika");
    Statement stmt = myconn.createStatement();
    ResultSet myResultSet = stmt.executeQuery("Select * from peopletable");
    if(myResultSet != null)
         while(myResultSet.next())
              int eid=myResultSet.getInt("id");
              String fname=myResultSet.getString("firstname");
              String lname=myResultSet.getString("lastname");
              String mail=myResultSet.getString("email");
    // end
    out.print(_jspx_html_data[2]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(30,10);to=(30,13)]
    out.print(eid);
    // end
    out.print(_jspx_html_data[3]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(31,10);to=(31,15)]
    out.print(fname);
    // end
    out.print(_jspx_html_data[4]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(32,10);to=(32,15)]
    out.print(lname);
    // end
    out.print(_jspx_html_data[5]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(33,10);to=(33,14)]
    out.print(mail);
    // end
    out.print(_jspx_html_data[6]);
    // begin [file="E:\\JavaWebServer2.0\\public_html\\Connect.jsp";from=(37,5);to=(43,0)]
    stmt.close();
    myconn.close();
    // end
    out.print(_jspx_html_data[7]);
    } catch (Throwable t) {
    if (out.getBufferSize() != 0)
    out.clear();
    throw new JspException("Unknown exception: ", t);
    } finally {
    if (!_jspx_cleared_due_to_forward)
    out.flush();
    _jspxFactory.releasePageContext(pageContext);
    -------------------error in browser----------------------
    Error during JSP page processing
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
         at java.lang.Throwable.(Compiled Code)
         at java.lang.Exception.(Compiled Code)
         at java.sql.SQLException.(SQLException.java:43)
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Compiled Code)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:3814)
         at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:1029)
         at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:145)
         at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:165)
         at java.sql.DriverManager.getConnection(Compiled Code)
         at java.sql.DriverManager.getConnection(DriverManager.java:126)
         at pagecompile.jsp._Connect._jspService(Compiled Code)
         at com.sun.server.http.pagecompile.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
         at javax.servlet.http.HttpServlet.service(Compiled Code)
         at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.runServlet(JspServlet.java:469)
         at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.processJspPage(JspServlet.java:259)
         at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.service(JspServlet.java:97)
         at javax.servlet.http.HttpServlet.service(Compiled Code)
         at com.sun.server.ServletState.callService(ServletState.java:226)
         at com.sun.server.ServletManager.callServletService(ServletManager.java:936)
         at com.sun.server.ProcessingState.invokeTargetServlet(ProcessingState.java:423)
         at com.sun.server.http.HttpProcessingState.execute(HttpProcessingState.java:79)
         at com.sun.server.http.stages.Runner.process(Runner.java:79)
         at com.sun.server.ProcessingSupport.process(Compiled Code)
         at com.sun.server.Service.process(Service.java:204)
         at com.sun.server.http.HttpServiceHandler.handleRequest(HttpServiceHandler.java:374)
         at com.sun.server.http.HttpServiceHandler.handleRequest(Compiled Code)
         at com.sun.server.HandlerThread.run(Compiled

    Backing up a moment, is there a particular reason that you're using the JDBC-ODBC bridge rather than using the Oracle JDBC driver?
    Have you taken a look at the JSP sample code available on OTN? I would start by making sure you can run that.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Loading a .jsp page from another .jsp page?

    Hi,
    I have following IF statement in "Main.jsp" page to load "ChangeJob.jsp" page. I tested and made sure that The IF condition was true(alert function executed), but ChangeJob.jsp didn't load.
    Did i miss something?
    Main.jsp
    <HTML>
    <% if ( (!(woSt.equals("Indirect"))) && (woSt.length()!=0) ){%>
    <SCRIPT>
    alert("click OK to load Changejob.jsp");
    document.form1.action="ChangeJob.jsp";
    document.form1.submit();
    </SCRIPT>
    <%} %>
    <BODY>
    <form name="form1">
    </form>
    </BODY>
    </HTML>

    Hi,
    The folloing code I am writing but in this my if loop is not working propery.
    the problem I am checking for this...
    if((!(progcode.equals(pall))) && (!(dcode.equals(dall))) && (!(yr.equals(yall))))
    in the belo program I am using but always it is going in to the loop. when they are equal and when they r not eqal....
    I have given compleate code in here pleace tell me hot to get it worked it properly.....
    <%@ page language="java" session="true"%>
    <%@ include file="connect.jsp"%>
    <%! ResultSet rs2,rs1;
    Statement stmt1,stmt2;
    %>
    <%
    String gpcode=null,pname=null,dname=null,total=null,totalyr=null,gtotal=null;
    int gdcode=0,gyear=0,gdata=0,deptcode=0;
    String pall=null,dall=null,yall=null;
    pall="all"; dall="99"; yall="1900";
    String progcode=request.getParameter("programname");
    String dcode=request.getParameter("departmentname");
    String yr=request.getParameter("year");
    deptcode=Integer.parseInt(dcode);
    int year=Integer.parseInt(yr);
    boolean flag=false;
    %> <%= progcode%><%=" "+ dcode%><%= " "+yr%><br>
    <%= pall%><%=" "+dall%><%=" " +yall%><br>
    <%= progcode%><%= deptcode%><%= year%>
    <%
    if((!(progcode.equals(pall))) && (!(dcode.equals(dall))) && (!(yr.equals(yall))))
    stmt=con.createStatement();
    rs=stmt.executeQuery("select * from data where progcode='"+progcode+"' and deptcode='"+deptcode+"' and year='"+year+"' ");
    flag=false;
    if(rs!=null){
    if(rs.next()){
    flag=true;
    if(flag){
    gpcode=rs.getString("progcode");
    gdcode=rs.getInt("deptcode");
    gyear=rs.getInt("year");
    gdata=rs.getInt("totalnoofstud");
    stmt1=con.createStatement();
    ResultSet trs=stmt1.executeQuery("select * from program where progcode='"+gpcode+"' ");
    if(trs.next()){
    pname=trs.getString(2);
    stmt2=con.createStatement();
    rs=stmt2.executeQuery("select * from department where deptcode='"+gdcode+"' ");
    if(rs.next()){
    dname=rs.getString("deptname");
    else {
    response.sendRedirect("viewdata.jsp?flag=false");
    stmt=con.createStatement();
    rs=stmt.executeQuery("select sum(totalnoofstud) from data where progcode='"+progcode+"' and deptcode='"+deptcode+"' ");
    if(rs.next()){
    total=rs.getString(1);
    stmt=con.createStatement();
    rs=stmt.executeQuery("select sum(totalnoofstud) from data where year='"+gyear+"' ");
    if(rs.next()){
    totalyr=rs.getString(1);
    else{
    stmt=con.createStatement();
    rs=stmt.executeQuery(" select sum(totalnoofstud) from data ");
    if(rs.next())
    gtotal=rs.getString(1);
    %>
    <html>
    <head><title>Passed Out Student Data</title></head>
    <body background="foggy2.jpg">
    <br><br>
    <%
    if(progcode!=pall && dcode!=dall && yr!=yall){%>
    <%@ include file="getdatasingle.jsp" %>
    <%}
    else{%>
    <br><br><br><center><b><font color="maroon" size=+3>Total Number Of Students Passed Out Till Now Are </font><font color="red" size=+3><%=" "+ gtotal%><
    /font></b></center>
    <%}%>
    <center>
    <input type="submit" name="ok" value="OK">
    </center>
    </body>
    </html>
    Regards,
    Madhavi

Maybe you are looking for

  • How do I limit the number of rows retrieved at a time using RefCursor?

    I have a PL/SQL package in use, that returns a REF CURSOR. This is currently being used in a Forms 6i application. Now I want to develop an ASP.NET web application that displays exactly the same information as my Forms 6i module. In fact those two ap

  • Getting a bad bind variable error while compiling a custom form in R12

    Hi, I am getting a bad bind variable error while compiling a custom form. I tried setting the forms_path variable and I am still getting the error. Can anyone please suggest what can be done? DECLARE BEGIN IF :parameter.p_line_ship_to = 'T' THEN IF :

  • Activated but now need to do a clean install

    I activated Server 2012 OEM yesterday on a new server and now find that I have delete the raid 5 and start over again. Will i be able to activate it again after reinstall?

  • Windows server 2008 r2 KB2871997 unexpected restarts

    Hi there, after I have installed KB2871997 on several Windows Servers we have a lot of unexpected restarts: Log Name:      System Source:        LsaSrv Date:          19.05.2014 11:19:24 Event ID:      5000 Task Category: None Level:         Error Ke

  • Bounce button becomes gray? Feature or bug?

    I discovered a tiny detail that I just can´t figure out: if I Ctrl - click and solo button in the Mixer, the Bnce button on the Output 1-2 channel strip becomes gray. I know that you can do exactly the above in order to disconnect the solo safe fader