Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am developing an application in javafx. i am using SQLITE as database.
i am fetching records from db and displaying date.
it is displaying 1970-01-01 if there is any date is present in databse.
can some help me to display correct date.

[Added from comment]
yeah

i have java class in that i am retrieving list
like this
Java
 public static Goal[] selectCompletedGoals(int goalType, int userID)
    {
        System.out.println("I am in selectCompletedGoals");
            int varResult=0;
            Statement stmt=null;
            ResultSet rs;
            String query;
            ArrayList results = new ArrayList();
            Goal goal=new Goal();
            Vector goalsVect = new Vector();
            try
            {
                Class.forName("org.sqlite.JDBC");
                        con = DriverManager.getConnection("jdbc:sqlite:EvolutionUniversity_Offline.db","EvolutionUniversity_Offline","");
                        stmt = con.createStatement();
               // Database db = new Database();
                //con = db.getConnection();

                query = "select * from Goal where GoalType="+goalType+" and UserID="+userID+" and GoalStatus=1 ";
                System.out.println("Querin in selectCompletedGoals is " + query);
                //stmt = con.createStatement();
                rs = stmt.executeQuery(query);
                System.out.println("result set in selectCompletedGoals is " + rs);
                System.out.println("result set count in selectCompletedGoals is " + rs.getRow());
               // if(rs.getRow()>0)
               // {
                    while(rs.next())
                    {
                        System.out.println("Completed date in goals1 "  + rs.getDate("completedDate"));
                        goal = extractGoalsData(rs);
                        goalsVect.add(goal);
                    }
                //}

            }
            catch(Exception ex)
            {
                System.out.println("Exception: "+ex);
                try{
                    stmt.close();
                    con.close();

                    }catch (SQLException ex1){
                        System.out.println(ex1 );
                    }
            }
            finally
            {
            try {
                stmt.close();
                con.close();
            } catch (SQLException ex) {
                Logger.getLogger(GoalsService.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
        Goal[] goalList = new Goal[goalsVect.size()];
        goalsVect.toArray(goalList);
        return goalList;
    }

    private static Goal extractGoalsData(ResultSet rs) throws Exception
     {
                Goal goal = new Goal();

                goal.goalID = rs.getInt("GoalID");
                goal.userID = rs.getInt("UserID");
                goal.goalTitle = rs.getString("GoalTitle");
                goal.goalDescription=rs.getString("GoalDescription");
                goal.createdDate = rs.getDate("CreatedDate");
                goal.lastModifiedDate = rs.getDate("LastModifiedDate");
                goal.completedDate = rs.getDate("CompletedDate");
                System.out.println("Completed date in goals "  + rs.getDate("CompletedDate"));
                //goal.goalKudos = rs.getInt("GoalKudos");
                goal.goalStatus=rs.getInt("GoalStatus");
                goal.goalsType = rs.getInt("GoalType");
                goal.blogID = rs.getInt("BlogID");

                return goal;
        }

and displaying in front end like this

goalsList = GoalsService.selectCompletedGoals(goalType, userID);

var todaysDate:String;
                        //goalDate.add(Calendar.DATE,1);
        var year:String;
        var month:String;
        var day:String;
        todaysDate = "{goalDate.get(Calendar.YEAR)}-{goalDate.get(Calendar.MONTH)}-{goalDate.get(Calendar.DATE)}";
        //journalDateText.text= dateString;
                        //println("Goal Completed Date {goalsList[i].completedDate}");
                        if(goalsList[i].completedDate.equals(""))
                        {
                            todaysDate=todaysDate;
                            println("Goal Completed Date {todaysDate}");
}
                        else
                        {
                            todaysDate=goalsList[i].lastModifiedDate.toString();
                            println("Goal Completed Date {goalsList[i].lastModifiedDate.toString()}");
                        }



                        insert HBox{
                            layoutY:40
                            layoutX:20
                        spacing:10
                        translateY: bind (sceneBucketList.height - container_height) / 2 - 120;
                        content:
                        [
                            bucketListTextBox[i]=TextBox
                            {
                                width:bind 150
                                text:goalsList[i].goalTitle
                                id:"bucketlistTextBox{i}"

                            },
                           bucketListCheckBox[i]= CheckBox
                            {
                                translateX:0
                                    id:"bucketlistCheckBox{i}"
                                    selected:status

                            },
                           bucketListLabel[i]= Label
                            {
                                translateX:50
                                id:"bucketlistLabel{i}"
                                //text:goalsList[i].completedDate.toString()
                                text:todaysDate
                            },
                         bucketListText[i]=  Text
                            {
                                id:"bucketlistText{i}"
                                content:"{goalsList[i].goalID}"
                                visible:false
                            }
                            
                        ]
                     } into listElements.content;
Posted
Updated 9-Sep-11 6:28am
v2

1 solution

Looks like you're using a date variable with a default value somewhere in your code. Try to debug to pinpoint the problem. If no success, post the code along the SQL you use.
 
Share this answer
 
Comments
Naseer Ahamed M 9-Sep-11 11:03am    
Thanks for your reply.
I am not using any default value.
if there is any date in record, then only it is displaying that 1970-01-01.
Wendelius 9-Sep-11 11:06am    
Could you post the relevant pieces of the code
Naseer Ahamed M 9-Sep-11 11:46am    
yeah

i have java class in that i am retrieving list
like this
public static Goal[] selectCompletedGoals(int goalType, int userID)
{
System.out.println("I am in selectCompletedGoals");
int varResult=0;
Statement stmt=null;
ResultSet rs;
String query;
ArrayList results = new ArrayList();
Goal goal=new Goal();
Vector goalsVect = new Vector();
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:EvolutionUniversity_Offline.db","EvolutionUniversity_Offline","");
stmt = con.createStatement();
// Database db = new Database();
//con = db.getConnection();

query = "select * from Goal where GoalType="+goalType+" and UserID="+userID+" and GoalStatus=1 ";
System.out.println("Querin in selectCompletedGoals is " + query);
//stmt = con.createStatement();
rs = stmt.executeQuery(query);
System.out.println("result set in selectCompletedGoals is " + rs);
System.out.println("result set count in selectCompletedGoals is " + rs.getRow());
// if(rs.getRow()>0)
// {
while(rs.next())
{
System.out.println("Completed date in goals1 " + rs.getDate("completedDate"));
goal = extractGoalsData(rs);
goalsVect.add(goal);
}
//}

}
catch(Exception ex)
{
System.out.println("Exception: "+ex);
try{
stmt.close();
con.close();

}catch (SQLException ex1){
System.out.println(ex1 );
}
}
finally
{
try {
stmt.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(GoalsService.class.getName()).log(Level.SEVERE, null, ex);
}
}
Goal[] goalList = new Goal[goalsVect.size()];
goalsVect.toArray(goalList);
return goalList;
}

private static Goal extractGoalsData(ResultSet rs) throws Exception
{
Goal goal = new Goal();

goal.goalID = rs.getInt("GoalID");
goal.userID = rs.getInt("UserID");
goal.goalTitle = rs.getString("GoalTitle");
goal.goalDescription=rs.getString("GoalDescription");
goal.createdDate = rs.getDate("CreatedDate");
goal.lastModifiedDate = rs.getDate("LastModifiedDate");
goal.completedDate = rs.getDate("CompletedDate");
System.out.println("Completed date in goals " + rs.getDate("CompletedDate"));
//goal.goalKudos = rs.getInt("GoalKudos");
goal.goalStatus=rs.getInt("GoalStatus");
goal.goalsType = rs.getInt("GoalType");
goal.blogID = rs.getInt("BlogID");

return goal;
}

and displaying in front end like this

goalsList = GoalsService.selectCompletedGoals(goalType, userID);

var todaysDate:String;
//goalDate.add(Calendar.DATE,1);
var year:String;
var month:String;
var day:String;
todaysDate = "{goalDate.get(Calendar.YEAR)}-{goalDate.get(Calendar.MONTH)}-{goalDate.get(Calendar.DATE)}";
//journalDateText.text= dateString;
//println("Goal Completed Date {goalsList[i].completedDate}");
if(goalsList[i].completedDate.equals(""))
{
todaysDate=todaysDate;
println("Goal Completed Date {todaysDate}");
Naseer Ahamed M 9-Sep-11 11:51am    
} else
{
todaysDate=goalsList[i].lastModifiedDate.toString();
println("Goal Completed Date {goalsList[i].lastModifiedDate.toString()}");
}



insert HBox{
layoutY:40
layoutX:20
spacing:10
translateY: bind (sceneBucketList.height - container_height) / 2 - 120;
content:
[
bucketListTextBox[i]=TextBox
{
width:bind 150
text:goalsList[i].goalTitle
id:"bucketlistTextBox{i}"

},
bucketListCheckBox[i]= CheckBox
{
translateX:0
id:"bucketlistCheckBox{i}"
selected:status

},
bucketListLabel[i]= Label
{
translateX:50
id:"bucketlistLabel{i}"
//text:goalsList[i].completedDate.toString()
text:todaysDate
},
bucketListText[i]= Text
{
id:"bucketlistText{i}"
content:"{goalsList[i].goalID}"
visible:false
}

]
} into listElements.content;
Naseer Ahamed M 9-Sep-11 11:52am    
you can see code in the above to comments.
that is displaying 1970-1-1 as a date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900