⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showtimedaoimpl.java

📁 一个前台基于AJAX
💻 JAVA
字号:
package com.demo2.persist;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.demo2.common.JdbcUtil;
import com.demo2.domain.Second;

/**
 * 数据库操作的实现类
 * 
 * @author liumei
 * 
 */
public class ShowTimeDaoImpl implements ShowTimeDao {
	/**
	 * 显示时间
	 */
	public List<Second> showTime() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "select * from countdown";

		List<Second> list = new ArrayList<Second>();

		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				Second sc = new Second();
				sc.setId(rs.getInt("id"));
               sc.setSecond(rs.getString("second"));

				list.add(sc);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	/**
	 * 更新时间
	 */
	public void updateTime() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "update countdown set second=second-1 where id =1 ";

		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.execute();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * 重置时间
	 */
	public void resetTime() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "update countdown set second=60 where id =1";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 加15秒
	 */

	public void addTime() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "update countdown set second=second+15 where id =1";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
  //服务器启动的时候把数据库的值设置为-1
	public void reverseTime() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "update countdown set second=-1 where id =1";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Second showTimes() {
		Connection conn = JdbcUtil.getConnection();
		String sql = "select * from countdown";

		Second sc = new Second();

		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				
				sc.setId(rs.getInt("id"));
               sc.setSecond(rs.getString("second"));

				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return sc;
	}

	public void updateTimeById(int id, String second) {
		Connection conn = JdbcUtil.getConnection();
		String sql="update countdown set second=? where id =?";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setString(1, second);
	        ps.setInt(2, id);
	        ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	}
		



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -