三月二十五日 安卓打卡app开发
今天完成了每月打卡次数统计功能
public static String count(String account) throws SQLException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; StringBuilder resultBuilder = new StringBuilder(); try { connection = JDBCUtils.getConn(); if (connection != null) { // 获取当前系统日期 Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); String formattedDate = dateFormat.format(calendar.getTime()); String query = "SELECT COUNT(*) AS count FROM infor WHERE Account = ? AND SUBSTRING(date, 1, 7) = ?"; statement = connection.prepareStatement(query); statement.setString(1, account); statement.setString(2, formattedDate); resultSet = statement.executeQuery(); if (resultSet.next()) { int count = resultSet.getInt("count"); System.out.println("统计结果: " + count); resultBuilder.append("打卡次数:").append(count).append("\n"); } } } finally { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } return resultBuilder.toString(); }

浙公网安备 33010602011771号