synchronous.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 4MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2017-11-09 10:12
    上传日期
通过wrapper将时间同步写入到windows服务 定时调用接口 同步本地时间
synchronous.rar
内容介绍
package com.synchronous.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.util.Date; import org.apache.log4j.Logger; import com.synchronous.dao.ILogDao; import com.synchronous.model.Log; public class LogDaoImpl implements ILogDao { private static final Logger LOGGER = Logger.getLogger(LogDaoImpl.class); @Override public Log findTopOne() { Statement statement = null; try { String sql = "select id, operate_date, message from t_log order by operate_date desc limit 1"; LOGGER.debug("查询语句:" + sql); Connection connection = ConnectionSqlite.getConnection(); if (connection != null) { statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql); Log log = null; while (rs.next()) { log = new Log(); log.setId(rs.getString(1)); log.setOperateDate(new Date(rs.getTimestamp(2).getTime())); log.setMessage(rs.getString(3)); } LOGGER.debug("查询结果:" + log); return log; } } catch (Exception e) { LOGGER.error("查询_log_异常", e); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } ConnectionSqlite.closeConnection(); } return null; } @Override public void insert(Log log) { PreparedStatement statement = null; try { String sql = "insert into t_log (id, operate_date, message) values (?, ?, ?)"; LOGGER.debug("插入语句:" + sql); LOGGER.debug("插入内容:" + log.toString()); Connection connection = ConnectionSqlite.getConnection(); if (connection != null) { statement = connection.prepareStatement(sql); statement.setString(1, log.getId()); statement.setTimestamp(2, new Timestamp(log.getOperateDate().getTime())); statement.setString(3, log.getMessage()); statement.execute(); } } catch (Exception e) { LOGGER.error("插入_log_异常", e); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } ConnectionSqlite.closeConnection(); } } @Override public void update(Log log) { PreparedStatement statement = null; try { String sql = "update t_log set operate_date = ?, message = ? where id = ?"; LOGGER.debug("更新语句:" + sql); LOGGER.debug("更新内容:" + log.toString()); Connection connection = ConnectionSqlite.getConnection(); if (connection != null) { statement = connection.prepareStatement(sql); statement.setTimestamp(1, new Timestamp(log.getOperateDate().getTime())); statement.setString(2, log.getMessage()); statement.setString(3, log.getId()); statement.execute(); } } catch (Exception e) { LOGGER.error("更新_log_异常", e); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } ConnectionSqlite.closeConnection(); } } @Override public void delete(String id) { PreparedStatement statement = null; try { String sql = "delete from t_log where id = ?"; LOGGER.debug("删除语句:" + sql); LOGGER.debug("删除键值:" + id); Connection connection = ConnectionSqlite.getConnection(); if (connection != null) { statement = connection.prepareStatement(sql); statement.setString(1, id); statement.execute(); } } catch (Exception e) { LOGGER.error("删除_log_异常", e); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } ConnectionSqlite.closeConnection(); } } }
评论
    相关推荐