Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to return the method value

 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
I have a method which returns a calculated value as below



I am taking the date from the database and then subtracting it with the current server time. So after that i am returning the etttime which will have the difference between the number of hours. So after this i have a condition which checks for this greater than as follows. (Condition's etttime should be greater than or equal to 2 hours then it should enter)


When i try to do it is giving a null pointer exception and also i am not able to retreive the etttime. And also rst.getTime(query) is returning a null value. So please help me out guys as to what to do? And also how to convert the rst returned date value into the corresponding hours. Thanks a lot in advance..
Akshay.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generally, if you get an error, it would VASTLY help if you post the full text of the error.

WHERE are you getting the NPE?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akshay Madhuranath wrote:When i try to do it is giving a null pointer exception

On which line, translated to this code? The exception stack trace tells you the exact line.

and also i am not able to retreive the etttime.

Why not? TellTheDetails.

And also rst.getTime(query) is returning a null value.

Really? I would have guessed it would throw an SQLException. ResultSet.getTime(String) requires the name of the field to return, not the query that was used to execute it. However, in your code the column has no value. rst.getTime(1) returns the first column (in your case the only column).

Also, something tells me that closing the statement before you handle the ResultSet is not going to work.

And also how to convert the rst returned date value into the corresponding hours.

Check out java.util.Calendar and its get method.
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:generally, if you get an error, it would VASTLY help if you post the full text of the error.

WHERE are you getting the NPE?


Hey im getting the NPE when i try to execute this.



i have a column name as date_modified in mantis_bug_history_table. So i am giving the bug id and then trying to get the date and compare it with the system date and check for the above mentioned condition. How to do this? Thanks in advance.
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Akshay Madhuranath wrote:When i try to do it is giving a null pointer exception

On which line, translated to this code? The exception stack trace tells you the exact line.

and also i am not able to retreive the etttime.

Why not? TellTheDetails.

And also rst.getTime(query) is returning a null value.

Really? I would have guessed it would throw an SQLException. ResultSet.getTime(String) requires the name of the field to return, not the query that was used to execute it. However, in your code the column has no value. rst.getTime(1) returns the first column (in your case the only column).

Also, something tells me that closing the statement before you handle the ResultSet is not going to work.

And also how to convert the rst returned date value into the corresponding hours.

Check out java.util.Calendar and its get method.





Hey im getting the NPE when i try to execute this.



i have a column name as date_modified in mantis_bug_history_table. So i am giving the bug id and then trying to get the date and compare it with the system date and check for the above mentioned condition. How to do this?

I dono why im not able to get the etttime value.

I looked into the package and did the convertion also but its not working. Its giving the same error. So in my code i've converted it to an int and then subtracting it. How to go about it?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the things that is wrong in your code is that you close the statement in line 11 before you read the values from the ResultSet in line 16.

You should close the ResultSet and the statement after you read the values.
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:One of the things that is wrong in your code is that you close the statement in line 11 before you read the values from the ResultSet in line 16.

You should close the ResultSet and the statement after you read the values.


Thanks i tried it and now its entering the loop. But i have another problem now. When i try to execute it its saying


Again i checked in the database. I've a table by mantis_bug_history_table name and also 'v a column by date_modified. But still its saying this. what to do? how to solve this?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I said:
Rob Prime wrote:
And also rst.getTime(query) is returning a null value.

Really? I would have guessed it would throw an SQLException. ResultSet.getTime(String) requires the name of the field to return, not the query that was used to execute it. However, in your code the column has no value. rst.getTime(1) returns the first column (in your case the only column).
 
Puja Mantri
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Akshay Madhuranath wrote:
Again i checked in the database. I've a table by mantis_bug_history_table name and also 'v a column by date_modified. But still its saying this. what to do? how to solve this?


then check if you have bug_id column in the mantis_bug_history_table table
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross posted
http://www.java-forums.org/advanced-java/29268-not-able-return-method-value.html
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:That's what I said:
Rob Prime wrote:
And also rst.getTime(query) is returning a null value.

Really? I would have guessed it would throw an SQLException. ResultSet.getTime(String) requires the name of the field to return, not the query that was used to execute it. However, in your code the column has no value. rst.getTime(1) returns the first column (in your case the only column).


Ya i changed that. Now i've the value i the result set object. So how return the value from the result set object>??
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puja Mantri wrote:
Akshay Madhuranath wrote:
Again i checked in the database. I've a table by mantis_bug_history_table name and also 'v a column by date_modified. But still its saying this. what to do? how to solve this?


then check if you have bug_id column in the mantis_bug_history_table table



Yes its there. Now im able to get the values in the result set. So now i've to take that result set value and then subtract with the other value. So how to return or retreive the date which;s stored in the result set object?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akshay, BeForthrightWhenCrossPostingToOtherSites. You should have informed us you had posted on the Java forums after first posting here.

You have now received the same answer from both Toll on the Java forums and me here - you must use a column name (or column index) to retrieve values from a result set. I again repeat, since you don't have a column name, use the column index 1.
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Akshay, BeForthrightWhenCrossPostingToOtherSites. You should have informed us you had posted on the Java forums after first posting here.

You have now received the same answer from both Toll on the Java forums and me here - you must use a column name (or column index) to retrieve values from a result set. I again repeat, since you don't have a column name, use the column index 1.


Ya ok.. Sorry i dint know. next time i'll c to it that i will inform before cross posting.
Yes i tried


Here i am getting the time which i need. So i need that value outside of the while loop. The value will be stored in the rst object. So how to get that value? Or how to return the value from the result set and compare with other variable? Thanks in advance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akshay Madhuranath wrote:Thanks i tried it and now its entering the loop. But i have another problem now. When i try to execute it its saying


That's because line 16 is wrong:

To the ResultSet.getTime() method you should pass the column name of the column that you want to get the value of, but you're passing the whole SQL query. It fails because there is no column named "select date_modified from mantis_bug_history_table where bug_id = ?". Do this instead:
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akshay Madhuranath wrote:Here i am getting the time which i need. So i need that value outside of the while loop. The value will be stored in the rst object. So how to get that value? Or how to return the value from the result set and compare with other variable?

Declare it before the loop and initialize it with null:

 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Akshay Madhuranath wrote:Here i am getting the time which i need. So i need that value outside of the while loop. The value will be stored in the rst object. So how to get that value? Or how to return the value from the result set and compare with other variable?

Declare it before the loop and initialize it with null:



Hey Now im getting a null value. ie im getting
Inside result set next method null
 
Akshay Madhuranath
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:
Akshay Madhuranath wrote:Thanks i tried it and now its entering the loop. But i have another problem now. When i try to execute it its saying


That's because line 16 is wrong:

To the ResultSet.getTime() method you should pass the column name of the column that you want to get the value of, but you're passing the whole SQL query. It fails because there is no column named "select date_modified from mantis_bug_history_table where bug_id = ?". Do this instead:


Hey man i tried this. Its saying But i checked in sql. That coulm exists man.. What to do now?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic