Results 1 to 11 of 11
  1. #1
    ME@SHARMA is offline Member
    Join Date
    Dec 2014
    Posts
    4
    Rep Power
    0

    Default Null is being shown when list containing data from database is displayed through jsp

    I'am new to java, this question may have been asked earlier but I'm not getting the exact answer.I want to add data from database into at and display it through jsp. But empty or null values is shown i.e no data is being displayed and when I execute the same sql query which is used in code in sql server then required output is displayed. My java code is:
    Java Code:
    public List < Alarm_Bean > get_Count(String system_Name)
    
    {
    
      if (system_Name.equals("MPS"))
    
      {
        try {
          con = getConnection();
    
          stmt = con.createStatement();
    
          String sql = " select c,system_name, 'TotalSum' as TotalSum, sum(s.c) as TotalValue from (SELECT   system_name, COUNT(distinct arrival_time) AS c FROM i2alarmlog WHERE Ack_status = 0 AND Direction='CAME' AND system_name in('I2-tciu database','i2-vcs logging','Indus1 Vacuum','Indus2 TCIU','Indus2 Vacuum','Septum_SIP2','TL3 Vacuum') GROUP BY system_name ) s     ";
    
          stmt.executeQuery(sql);
          rs = stmt.getResultSet();
    
    
    
          while (rs.next()) {
            Alarm_Bean obj = new Alarm_Bean();
    
    
            obj.setSystem_name(rs.getString("system_name"));
    
            obj.setC(rs.getString("c"));
            at.add(obj);
          }
    
        } catch (Exception e) {
          System.out.println("\nException " + e);
        } finally {
          closeConnection(stmt, rs, con);
        }
      }
      //System.out.println(at);
    
      return at;
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Null is being shown when list containing data from database is displayed through

    Any exception in your logs?

    The second thing is to log everything in that method.
    Log entering the result set loop, and the values in the columns for each row.
    Log the values returned in the List.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    ME@SHARMA is offline Member
    Join Date
    Dec 2014
    Posts
    4
    Rep Power
    0

    Default Re: Null is being shown when list containing data from database is displayed through

    I didn't get you.Will you please elaborate it with example or code sample.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Null is being shown when list containing data from database is displayed through

    I'm simply pointing out that you need to log everything in order to debug your code.
    At the moment you are making assumptions about what is going on without (as far as I can see) enough logging in the code to tell you exactly what is happening.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    286
    Rep Power
    11

    Default Re: Null is being shown when list containing data from database is displayed through

    Does the following print anything?

    System.out.println("\nException " + e); and better use e.printStackTrace() to get the detailed exception stack.
    Swastik

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Null is being shown when list containing data from database is displayed through

    Java Code:
    at.add(obj); // where does 'at' come from?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    ME@SHARMA is offline Member
    Join Date
    Dec 2014
    Posts
    4
    Rep Power
    0

    Default Re: Null is being shown when list containing data from database is displayed through

    no ,nothing is being printed .at is defined as a global variable as:-
    Java Code:
    private List<String> at= new ArrayList<String>();

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Null is being shown when list containing data from database is displayed through

    If it is a class property, then why are you returning it from the method? The way you have it now, each call to get_count will just keep appending new elements to this one list.

    That is probably nothing to do with your current problem, but it is a design smell that might lead to other problems if you're not careful.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    ME@SHARMA is offline Member
    Join Date
    Dec 2014
    Posts
    4
    Rep Power
    0

    Default Re: Null is being shown when list containing data from database is displayed through

    Ok, but how to resolve this current problem..??
    Last edited by ME@SHARMA; 12-11-2014 at 01:22 PM.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Null is being shown when list containing data from database is displayed through

    You solve it like you solve all other problems, first you need to find the cause. Hence the replies for doing more debugging.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Null is being shown when list containing data from database is displayed through

    Quote Originally Posted by ME@SHARMA View Post
    no ,nothing is being printed
    Show us the code with the extra logging added.
    Include a logging statement at the very start of the method, just to make sure this is actually being called.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to index an array so that specific data can be shown
    By OldSkoolBray in forum New To Java
    Replies: 1
    Last Post: 08-06-2014, 12:42 AM
  2. Replies: 12
    Last Post: 04-27-2014, 06:12 PM
  3. need last help - price list not shown up
    By Cyberoxy in forum Advanced Java
    Replies: 5
    Last Post: 06-29-2011, 03:08 PM
  4. Replies: 1
    Last Post: 05-16-2011, 02:19 PM
  5. Replies: 1
    Last Post: 09-15-2008, 09:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •