Hi,

public void getTasksList(ArrayList<PerformTask> TasksList) {
	// TODO Auto-generated method stub
	try{
		Class.forName("com.mysql.jdbc.Driver");
		Connection cn=DriverManager.getConnection("jdbc:mysql:///test","root", "admin");
		Statement st= cn.createStatement();
		String s1 = "Select * from perform_task";
		ResultSet rs = st.executeQuery(s1);
		System.out.println("Comes Here !! ");
		while(rs.next()){
			rs.getDate("DateOfTask");
			java.util.Date jDate = new java.util.Date(rs.getDate("DateOfTask").getTime());
			TasksList.add(new PerformTask(rs.getInt("TaskID"), rs.getInt("PersonID") , jDate ,rs.getString("TaskDescription"),rs.getInt("TotalEffort"),rs.getString("TaskName")));
		}
	}catch(Exception e){
		e.printStackTrace();
	}
}

I get time value as 00:00:00 GMT +5:30 . Not getting the value actually inserted.
Is there a way to get the time from the java.sql.Date object returned by rs.getDate();.?

This is my code for inserting into the table.

The insertion is working perfectly fine and the type of "DateOfTask" column is DATETIME.

public boolean InsertPerformData(int taskID, int personID, Date data,
		String value, int intValue, String taskName) {
	try
	{
	java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String datestring = sdf.format(data);
	Class.forName("com.mysql.jdbc.Driver");
	Connection cn=DriverManager.getConnection("jdbc:mysql:///test","root", "admin");
	Statement st= cn.createStatement();
	String s1 = "Insert into perform_task(TaskID , PersonID , DateOfTask , TaskDescription , TotalEffort , TaskName) values("+taskID+","+personID+",'"+datestring+"','"+value+"',"+intValue+",'"+taskName+"')";
	int result = st.executeUpdate(s1);
	if(result == 0){
		System.out.println("Insert Failed");
		return false;
	}
	else{
		return true;
	}
	}catch(Exception e){
		e.printStackTrace();
		return false;
	}
}

java.Util.Date myDate = rs.getDate("DateOfTask");

for various column def on DbSide Datetime, date, time, TImestmpt

@mKorbel.

I get the date value that was inserted previously. Only the time value is 00:00:00 . The above method suggested by you also gives me just the date .

Edited 5 Years Ago by adarshcu: n/a

i guess java.sql.Date is timeless date, so you that would obviously give zero time values. Use java.sql.Timestamp tmp = rs.getTimestamp("DateOfTask") like @masijade posted.

Edited 4 Years Ago by rahul.pedduri

This article has been dead for over six months. Start a new discussion instead.