首页>代码>java牛每日注册用户数>/1323902094410752.java
package com.javaniu;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class java牛每日注册用户数 {
	public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

	public static Map<String, Integer> stat() {
		Map<String, Integer> map = new HashMap<String, Integer>();
		Connection conn = null;
		try {
			String userName = "root";
			String password = "111111";
			String jdbcurl = "jdbc:mysql://localhost:3306/javaniu2?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select create_time from user where status=2";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				Date _createTime = rs.getDate("create_time");
				String createTime = format.format(_createTime);
				Integer count = map.get(createTime);
				if (count == null) {
					count = 0;
				}
				count++;
				map.put(createTime, count);
				System.out.println(createTime+"="+count);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) {
				}
			}
		}
		return map;
	}

	public static void write(String path, String content, String encoding)
			throws IOException {
		File file = new File(path);
		file.delete();
		file.createNewFile();
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream(file), encoding));
		writer.write(content);
		writer.close();
	}

	public static void main(String[] args) throws IOException {
		File file = new File("stat.txt");
		file.delete();
		file.createNewFile();
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream(file), "utf-8"));
		Map<String, Integer> map = stat();
		for (String date : map.keySet()) {
			Integer count = map.get(date);
			writer.write(date + "," + count + "\n");
		}
		writer.close();
	}
}
最近下载更多
wlh2015  LV20 2018年8月17日
故事_sun  LV26 2018年5月25日
sowang  LV9 2018年4月12日
hackxhao  LV15 2018年3月8日
zdd123456  LV9 2017年12月2日
branice  LV18 2017年8月26日
qiugeqiuge  LV6 2017年6月27日
Sword  LV3 2015年4月17日
tzh1247  LV5 2015年1月4日
nlyjava  LV11 2014年12月25日
最近浏览更多
java小书童  LV18 2023年9月27日
Evil_dong  LV4 2023年3月30日
2428284819  LV1 2021年12月31日
TWOBTWOB  LV1 2021年12月24日
543666826  LV33 2021年11月21日
liqi666  LV7 2021年10月29日
小白小怪  LV10 2021年6月8日
xmfsd123  LV2 2021年1月29日
yyd-yun  LV9 2020年12月29日
xueernihao  LV4 2020年12月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友