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;
}
}