Use JSP + JavaBean development mode to query a sales volume

Source: Internet
Author: User

The Sales class of the vo package: 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;} DBManager class in the dao package: package com. dao; import java. SQL. connect Ion; 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 = DriverMa Nager. 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. salesDao class in the printStackTrace () ;}}} dao package: 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.exe cuteQuery (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: <% @ 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">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.