Results 1 to 12 of 12
- 05-28-2010, 05:06 AM #1
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
Not able to return the method value
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)Java Code:private static long getETTTime(long bugID,Connection con){ int etttime=0; try{ String query = "select max(date_modified) from mantis_bug_history_table where bug_id= ?"; PreparedStatement pst = con.prepareStatement(query); pst.setLong(1,bugID); ResultSet rst = pst.executeQuery(); pst.close(); System.out.println("RST value = "+rst); SimpleDateFormat sdf = new SimpleDateFormat("hhmm"); java.util.Date date1 = rst.getTime(query); int datedb = Integer.parseInt(sdf.format(date1)); java.util.Date date = new java.util.Date(); int datesys = Integer.parseInt(sdf.format(date)); etttime=(datesys-datedb); }catch(Exception e){ e.printStackTrace(); } return etttime; }
Java Code:If((a==b) && ((getETTTime(169587, con))>=0200)) { //Statements to be executed }
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.
- 05-28-2010, 09:03 AM #2
Please post the code with code tags...not at all understandable.
Before retrieval of ResultSet ,how can you close the PreparedStatement object?
Have you checked is there any records in database.Ramya:cool:
- 05-28-2010, 09:21 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
OK, as already pointed out you've closed the statement before doing anything with the result set. You should have an exception. Though that probably depends on the driver, I would expect some form of state exception since the resultset will have been invalidated by the closing of the statement.
Secondly, the resources (resultset then statement) should be closed in a finally block, not in the try block.
- 05-28-2010, 10:04 AM #4
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
Thanks i tried it and now its entering the loop and coming till there. 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?Java Code:java.sql.SQLException: Column 'select date_modified from mantis_bug_history_table where bug_id = ? ' not found.
- 05-28-2010, 10:05 AM #5
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
Thanks i tried it and now its entering the loop and coming till there. 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?Java Code:java.sql.SQLException: Column 'select date_modified from mantis_bug_history_table where bug_id = ? ' not found.
- 05-28-2010, 10:05 AM #6
Iam not able to see the code above....
what iam telling here is whatever query u are giving here ,just run directly in the database sql window and check...Let us see...Last edited by RamyaSivakanth; 05-28-2010 at 10:26 AM.
Ramya:cool:
- 05-28-2010, 10:25 AM #7
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
This's my method.
And im calling the method in this if condition.Java Code:private static long getETTTime(long bugID,Connection con){ int etttime=0; PreparedStatement pst = null; try{ String query = "select max(date_modified) from mantis_bug_history_table where bug_id= ?"; PreparedStatement pst = con.prepareStatement(query); pst.setLong(1,bugID); ResultSet rst = pst.executeQuery(); System.out.println("RST value = "+rst); SimpleDateFormat sdf = new SimpleDateFormat("hhmm"); java.util.Date date1 = rst.getTime(query); int datedb = Integer.parseInt(sdf.format(date1)); java.util.Date date = new java.util.Date(); int datesys = Integer.parseInt(sdf.format(date)); etttime=(datesys-datedb); }catch(Exception e){ e.printStackTrace(); } finally{ try{ pst.close(); }catch(Exception e){ e.printStackTrace(); } }return etttime; }
Java Code:If((a==b) && ((getETTTime(169587, con))>=0200)) { //Statements to be executed }Last edited by dmakshay2002; 05-28-2010 at 10:27 AM.
- 05-28-2010, 10:32 AM #8
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
- 05-28-2010, 11:17 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
rst.getTime(query);
The getters of a resultset expect a column name.
You are giving it the whole query.
Have you been through the Sun JDBC tutorials?
- 05-28-2010, 12:11 PM #10
- 05-28-2010, 02:02 PM #11
Member
- Join Date
- May 2010
- Posts
- 6
- Rep Power
- 0
Hey i've given everythin.
Now its perfectly printing the date modified. But i need it to retrieve from the result set to compare it with System date variable. So now i've to compare it with the system date variable. so how to do it?Java Code:System.out.println("After the prepared statement long method"); ResultSet rst = pst.executeQuery(); while (rst.next()) { Date s = rst.getTime(1); System.out.println("Inside result set next method"+s); }
- 05-28-2010, 02:07 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Method won't return value
By footyvino in forum New To JavaReplies: 2Last Post: 03-26-2010, 10:49 AM -
can't return a value from a method / jdbc
By tascoa in forum JDBCReplies: 3Last Post: 10-15-2009, 01:02 PM -
return a null method
By valoyivd in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:19 PM -
Return question in a method.
By MetalGear in forum New To JavaReplies: 1Last Post: 01-13-2008, 04:45 AM -
Return value of method
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks