Request to check timestamp

In my java project I want to list the values ​​of a table

programtable .

The table has four fields programid , program_name , start and enddate .

I want to list the details of the programs made today.

The start and end dates are in the database data type as TIMESTAMP . Help me find a request to get detailed information about the programs made today.

I am adding my code to this. I am using this method. But its not working

String todayDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
todayDatem=todayDate+" 00:00:00";
todayDaten=todayDate+" 23:59:59";
Timestamp timestamp1 = Timestamp.valueOf(todayDatem);
Timestamp timestamp2 = Timestamp.valueOf(todayDaten);
System.out.println("timestamp1:"+timestamp1+timestamp2);
String sql3 = "select * form programtable where startdate between '"+timestamp1+"' and '"+timestamp2+"'";  
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);  
List<programmodel> pgm = jdbcTemplate.query(sql3, ParameterizedBeanPropertyRowMapper.newInstance(programmodel .class));
+4
source share
2 answers

:

    java.sql.Date d1 = new java.sql.Date(System.currentTimeMillis());
    java.sql.Date d2 = new java.sql.Date(System.currentTimeMillis() + 24  * 3600 * 1000);
    String sql3 = "select * from programtable where startdate between ? and ?"; 
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);  
    List<programmodel> pgm = jdbcTemplate.query(sql3, ParameterizedBeanPropertyRowMapper.newInstance(programmodel.class), d1, d2);
+2

 SELECT *
 FROM programtable
 WHERE startdate = CURDATE() AND enddate = CURDATE();

 SELECT *
 FROM programtable
 WHERE startdate = CURDATE();

 SELECT *
 FROM programtable
 WHERE enddate = CURDATE();
0

All Articles