i pulling data remote sqlserver local mysql server using jdbc .
in remote sqlserver server have 2 columns
name count
in local mysql have 3 columns made
name count time_stamp
time_stamp datetime datatype
i pulling data using below insert code segment,
while (rs.next()) { string zonename = rs.getstring("name"); int zonecount = rs.getint("count"); string insertsql = "insert occupancy.occupancy_phase_2(name,count)values('"+zonename+"',"+zonecount+")"; pstmt = con2.preparestatement(insertsql); pstmt.executeupdate();
i want add timestamp insert query @ every run .
how can this.
you can use now() function of mysql currentdate , insert (here assuming database server in same timezone application server)
you can use following query string
string insertsql = "insert occupancy.occupancy_phase_2(name,count,time_stamp)values('"+zonename+"',"+zonecount+", now())";
also directly give values instead of specifying column
string insertsql = "insert occupancy.occupancy_phase_2 values('"+zonename+"',"+zonecount+", now())";
note:
while using prepared statement use preparedstatement
instance set query parameters, below
string insertsql = "insert occupancy.occupancy_phase_2 values(?,?, now())"; preparedstatement ps = connection.preparestatement(insertsql); ps.setstring(1, zonename); ps.setint(2, zonecount);
Comments
Post a Comment