Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:43:01+00:00 2026-05-24T06:43:01+00:00

when calling the following function I get an error. The HQL query functions downloading

  • 0

when calling the following function I get an error. The HQL query functions downloading data from the database, but unfortunately I get an error:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
    at java.util.ArrayList.RangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at com.example.server.RaportGenerator.checkParam(RaportGenerator.java:103)
    at com.example.server.RaportGenerator.doGet(RaportGenerator.java:58)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

And this is my function:

protected boolean checkParam(String login, String sid) {
    boolean result = false;
    List listOfData;
    try {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Query query = session.createQuery("Select u.login, u.sid from User u Where u.login = :login");
        query.setParameter("login",login);
        listOfData = query.list();
        String sidDb = listOfData.get(1).toString();
        if (sid == sidDb) {
            result = true;  
        }
        session.close();
    } catch (HibernateException e) {
        e.printStackTrace();
    }
    return result;
}

RaportGenerator.java:103 is:


String sidDb = listOfData.get(1).toString();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:43:02+00:00Added an answer on May 24, 2026 at 6:43 am

    There are multiple things wrong with this code:

    • You’re asking for element 1, which is the second element. I suspect you actually meant get(0) to get the first element.
    • That will still fail if the user’s login doesn’t exist, of course… you should use listOfData.size() first to check.
    • You don’t need the result variable – just return when you know the answer.
    • The listOfData variable can be declared in a tighter scope, which is generally good practice.
    • You should probably be closing the session in a finally block, from what I remember.
    • You shouldn’t be testing string equality with ==.
    • You probably shouldn’t be catching HibernateException at this point in your code, and even if you do, you should probably use a better logging mechanism.

    Here’s a code sample with most of this cleaned up.

    protected boolean checkParam(String login, String sid) {
        Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            Query query = session.createQuery
                ("Select u.login, u.sid from User u Where u.login = :login");
            query.setParameter("login",login);
            List listOfData = query.list();
            return listOfData.size() == 1 
                   && listOfData.get(0).toString().equals(sidDb);
        } catch (HibernateException e) {
            // Do you really just want to print the stack trace to stdout?
            // I would probably change the method to allow the exception
            // to bubble up...
            e.printStackTrace();
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that is pulling data from a database. The ajax
I get the following error: Fatal error: Call to undefined function getAvnet() in C:\xampp\htdocs\ems\app\controllers\queries_controller.php
In defining my Element class I get the following error: no matching function for
I am following these steps, but I continue to get an error and don't
Using the following JQuery/AJAX function I'm calling a partial view when an option is
I am (successfully) calling the Windows FilterSendMessage function in c# using the following pinvoke
I am currently calling the following line of code: java.net.URL connection_url = new java.net.URL(http://<ip
I'm calling the following URL using YQL http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22UTG.L%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=cbfunc this returns the following in JSON
Am getting following error message on calling WCF service: The formatter threw an exception
I'm getting the following error when calling a stored procedure: Cannot find the object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.