Results 1 to 11 of 11
- 12-11-2014, 10:56 AM #1
Member
- Join Date
- Dec 2014
- Posts
- 4
- Rep Power
- 0
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; }
- 12-11-2014, 12:06 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
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 **
- 12-11-2014, 12:14 PM #3
Member
- Join Date
- Dec 2014
- Posts
- 4
- Rep Power
- 0
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.
- 12-11-2014, 12:20 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
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 **
- 12-11-2014, 12:37 PM #5
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 286
- Rep Power
- 11
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
- 12-11-2014, 12:50 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
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
- 12-11-2014, 12:56 PM #7
Member
- Join Date
- Dec 2014
- Posts
- 4
- Rep Power
- 0
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>();
- 12-11-2014, 01:00 PM #8
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
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
- 12-11-2014, 01:10 PM #9
Member
- Join Date
- Dec 2014
- Posts
- 4
- Rep Power
- 0
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.
- 12-11-2014, 01:29 PM #10
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 12
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
- 12-11-2014, 03:07 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
Re: Null is being shown when list containing data from database is displayed through
Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads
-
How to index an array so that specific data can be shown
By OldSkoolBray in forum New To JavaReplies: 1Last Post: 08-06-2014, 12:42 AM -
Trying to get data from previous Assignment to be displayed in new one using a GUI
By timalloy in forum New To JavaReplies: 12Last Post: 04-27-2014, 06:12 PM -
need last help - price list not shown up
By Cyberoxy in forum Advanced JavaReplies: 5Last Post: 06-29-2011, 03:08 PM -
sql: store data in list or constantly ask the database?
By jojo in forum New To JavaReplies: 1Last Post: 05-16-2011, 02:19 PM -
IObservableValue issue with data displayed in row(s)
By jaydev in forum SWT / JFaceReplies: 1Last Post: 09-15-2008, 09:21 PM
Bookmarks