第二次冲刺 08
今日主要实现了项目的优化。
主要进行了页面的处理。
package com.example.math.repositiory; /* * 购买信息辅助类 * */ import com.example.math.R; import com.example.math.bean.buyBean; import com.example.math.jdbc.JDBCtools; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Buy_res { // 查询当日收益 public static int total(String username, String time) throws Exception { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; int num = 0; try { connection = JDBCtools.getConnect(); String sql = "select SUM(price) from car_buy where user_phone = ? and time like '%" + time + "%'"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int total = resultSet.getInt(1); num = total; } } catch (SQLException e) { throw new RuntimeException(e); } finally { JDBCtools.release(connection, preparedStatement, resultSet); } return num; } // 累计收益 public static int top_total(String username) throws Exception { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; int num = 0; try { connection = JDBCtools.getConnect(); String sql = "select SUM(price) from car_buy where user_phone = ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int total = resultSet.getInt(1); num = total; } } catch (SQLException e) { throw new RuntimeException(e); } finally { JDBCtools.release(connection, preparedStatement, resultSet); } return num; } public static List<buyBean> findDg(String username, String time) throws Exception { List<buyBean> list = new ArrayList<>(); Connection connection = JDBCtools.getConnect(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; String sql = "select name,price,time from car_buy where user_phone = ? and time like '%" + time + "%'"; try { preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { String name = resultSet.getString("name"); int price = resultSet.getInt("price"); String time1 = resultSet.getString("time"); buyBean buy_bean = new buyBean(username, name, price, time1); list.add(buy_bean); } } catch (SQLException e) { throw new RuntimeException(e); } finally { JDBCtools.release(connection, preparedStatement, resultSet); } return list; } /** * 获取某一月具体收入 */ public static int getSunMoneyOneMonth(String username, String time) throws Exception { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; int num = 0; try { connection = JDBCtools.getConnect(); String sql = "select SUM(price) from car_buy where user_phone = ? and time like '%" + time + "%'"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int total = resultSet.getInt(1); num = total; } } catch (SQLException e) { throw new RuntimeException(e); } finally { JDBCtools.release(connection, preparedStatement, resultSet); } return num; } /** * 获取某一月共几笔收入 */ public static int getCountItemOneMonth(String username, String time) throws Exception { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; int num = 0; try { connection = JDBCtools.getConnect(); String sql = "select count(price) from car_buy where user_phone = ? and time like '%" + time + "%'"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { int total = resultSet.getInt(1); num = total; } } catch (SQLException e) { throw new RuntimeException(e); } finally { JDBCtools.release(connection, preparedStatement, resultSet); } return num; } }
package queren; import toolse.Tool; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; public class Daos { public List<Things> search(){ List<Things> list = new ArrayList<>(); try { Connection conn =Tool.getConnection(); String sql="select * from car_send " ; PreparedStatement pstmt = conn.prepareStatement(sql); // pstmt.setString(1, mer); ResultSet rs = pstmt.executeQuery(); while(rs.next()){ Things lu = new Things(); lu.setMer_phone(rs.getString("mer_phone")); lu.setTime(rs.getString("time")); lu.setAddress(rs.getString("address")); lu.setUser_phone(rs.getString("user_phone")); lu.setName(rs.getString("name")); lu.setTotal(rs.getInt("total")); lu.setFlag(rs.getInt("judge_bu")); list.add(lu); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return list; } public List<Things> searches(String name ,String time,String phone,String mer ){ List<Things> list = new ArrayList<>(); try { Connection conn =Tool.getConnection(); Statement state = null; String sql="select * from car_send where mer_phone= ? and name like '%"+name+"%' and time like '2023%"+time+"%' and user_phone like '%"+phone+"%' " ; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, mer); ResultSet rs = pstmt.executeQuery(); while(rs.next()){ Things lu = new Things(); lu.setMer_phone(rs.getString("mer_phone")); lu.setTime(rs.getString("time")); lu.setAddress(rs.getString("address")); lu.setUser_phone(rs.getString("user_phone")); lu.setName(rs.getString("name")); lu.setTotal(rs.getInt("total")); lu.setFlag(rs.getInt("judge_bu")); list.add(lu); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return list; } public int js(String name,String phone) { int price=0; try { Connection conn =Tool.getConnection(); String sql="select * from car_commodity where name = ? and user_phone = ?" ; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, name); pstmt.setString(2,phone); ResultSet rs = pstmt.executeQuery(); while(rs.next()){ price=rs.getInt("price"); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { System.out.println("发生错误"); e.printStackTrace(); } return price; } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端