用JSP+JavaBean开发模式实现一个销售额的查询
vo包的Sales类:package com.vo;public class Sales {public String salestime;public float salesnum;public String getSalestime() {return salestime;}public void setSalestime(String salestime) {this.salestime = salestime;}public float getSalesnum() {return salesnum;}public void setSalesnum(float salesnum) {this.salesnum = salesnum;}}dao包中的DBManager类:package com.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DbManager {private static String URL = "jdbc:mysql://localhost:3306/sales";private static String USER = "root";private static String PWD = "root";public static Connection getConn(){Connection conn = null;try {Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection(URL,USER,PWD);} catch (SQLException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();}return conn;}public static void closeAll(Connection conn,Statement ste,ResultSet rs){if(rs != null){try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if(ste !=null){try {ste.close();} catch (SQLException e) {e.printStackTrace();}}if(conn !=null){try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}dao包中的SalesDao类:package com.dao;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import com.vo.Sales;public class SalesDao {public List<Sales> find(String month) {Connection con = null;Statement state = null;ResultSet resultSet = null;List<Sales> list = null;String sql = "select * from sales where salestime like '" + month + "-%'" ;con = DbManager.getConn();try {state = con.createStatement();resultSet = state.executeQuery(sql);while(resultSet.next()){if(null == list){list = new ArrayList<Sales>();}Sales sales = new Sales();sales.setSalestime(resultSet.getString("salestime"));sales.setSalesnum(resultSet.getFloat("salesnum"));list.add(sales);}} catch (SQLException e) {e.printStackTrace();}finally{DbManager.closeAll(con, state, resultSet);}return list;}}index.jsp页面:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><form action="show.jsp" method="post">请选择查询的月份:<select name="month">补充:Web开发 , Jsp ,
上一个:EL表达式
下一个:jsp获得本地及serverIP的方法
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- jsp+javaBean中Column 'ordersPrice' specified twice的错误
- Java TCP/IP Socket网络编程系列
- 大家来讨论一下我到底该用什么好?Swing 还是 JavaFX
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- spring 获取上下文问题
- SSH 导入导出excel 谁有这块的资料吗?
- Ext TreePanel 刷新问题
- springmvc 加载一个jsp页面执行多个方法 报404
- checkbox数组action怎么向页面传值