aspose file tools*
The moose likes Java in General and the fly likes Not able to return the method value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Not able to return the method value" Watch "Not able to return the method value" New topic
Author

Not able to return the method value

Akshay Madhuranath
Greenhorn

Joined: Nov 29, 2009
Posts: 20
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

Joined: Oct 02, 2003
Posts: 11411
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Akshay Madhuranath
Greenhorn

Joined: Nov 29, 2009
Posts: 20
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

Joined: Nov 29, 2009
Posts: 20
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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Akshay Madhuranath
Greenhorn

Joined: Nov 29, 2009
Posts: 20
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Sep 24, 2009
Posts: 15

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

Joined: May 03, 2008
Posts: 4642
    
    5

Cross posted
http://www.java-forums.org/advanced-java/29268-not-able-return-method-value.html


luck, db
There are no new questions, but there may be new answers.
Akshay Madhuranath
Greenhorn

Joined: Nov 29, 2009
Posts: 20
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

Joined: Nov 29, 2009
Posts: 20
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Nov 29, 2009
Posts: 20
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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Nov 29, 2009
Posts: 20
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

Joined: Nov 29, 2009
Posts: 20
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to return the method value