From e786e94e8c3ca34a1c43b801557b0ffa387c74a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E8=B0=83?= <3084898776@qq.com> Date: Fri, 26 Jul 2024 09:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++ .idea/$PROJECT_FILE$ | 11 + .idea/.gitignore | 8 + .idea/encodings.xml | 8 + .idea/inspectionProfiles/Project_Default.xml | 5 + .idea/misc.xml | 30 ++ .idea/qaplug_profiles.xml | 465 ++++++++++++++++++ pom.xml | 24 + src/main/java/com/bwie/Demo.java | 23 + src/main/java/com/bwie/Main.java | 17 + src/main/java/com/bwie/dmain/Bill.java | 54 ++ .../java/com/bwie/service/BillManager.java | 53 ++ 12 files changed, 736 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/$PROJECT_FILE$ create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/qaplug_profiles.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/bwie/Demo.java create mode 100644 src/main/java/com/bwie/Main.java create mode 100644 src/main/java/com/bwie/dmain/Bill.java create mode 100644 src/main/java/com/bwie/service/BillManager.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/$PROJECT_FILE$ b/.idea/$PROJECT_FILE$ new file mode 100644 index 0000000..58b7e3e --- /dev/null +++ b/.idea/$PROJECT_FILE$ @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63574ec --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8d66637 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f25c597 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,30 @@ + + + + + + { + "isMigrated": true +} + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml new file mode 100644 index 0000000..3dfd21f --- /dev/null +++ b/.idea/qaplug_profiles.xml @@ -0,0 +1,465 @@ + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..39f9825 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + com.bwie + day_08 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + mysql + mysql-connector-java + 8.0.33 + + + + diff --git a/src/main/java/com/bwie/Demo.java b/src/main/java/com/bwie/Demo.java new file mode 100644 index 0000000..766ba70 --- /dev/null +++ b/src/main/java/com/bwie/Demo.java @@ -0,0 +1,23 @@ +package com.bwie; + +import com.bwie.dmain.Bill; +import com.bwie.service.BillManager; + +import java.util.List; + +/** + * @author Lenovo + */ +public class Demo { + public static void main(String[] args) { + BillManager billManager = new BillManager(); + List bills = billManager.selectAll(); + for (Bill bill : bills) { + System.out.println( + "序号:"+bill.getId() + +",账单金额:"+bill.getBillMoney() + +",账单日期:"+bill.getBillDate() + ); + } + } +} diff --git a/src/main/java/com/bwie/Main.java b/src/main/java/com/bwie/Main.java new file mode 100644 index 0000000..6f2a6ed --- /dev/null +++ b/src/main/java/com/bwie/Main.java @@ -0,0 +1,17 @@ +package com.bwie; + +import com.bwie.service.BillManager; + +/** + * @author Lenovo + */ +public class Main { + public static void main(String[] args) { + BillManager billManager = new BillManager(); + Boolean i =billManager.billAdd(123.00); + if(i){ + throw new RuntimeException("插入失败"); + } + System.out.println("插入成功"); + } +} diff --git a/src/main/java/com/bwie/dmain/Bill.java b/src/main/java/com/bwie/dmain/Bill.java new file mode 100644 index 0000000..db485f7 --- /dev/null +++ b/src/main/java/com/bwie/dmain/Bill.java @@ -0,0 +1,54 @@ +package com.bwie.dmain; + +import java.util.Date; + +/** + * @author Lenovo + */ +public class Bill { + private Integer id; + private Date billDate; + private double billMoney; + + @Override + public String toString() { + return "Bill{" + + "id=" + id + + ", billDate=" + billDate + + ", billMoney=" + billMoney + + '}'; + } + + public Bill() { + } + + public Bill(Integer id, Date billDate, double billMoney) { + this.id = id; + this.billDate = billDate; + this.billMoney = billMoney; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Date getBillDate() { + return billDate; + } + + public void setBillDate(Date billDate) { + this.billDate = billDate; + } + + public double getBillMoney() { + return billMoney; + } + + public void setBillMoney(double billMoney) { + this.billMoney = billMoney; + } +} diff --git a/src/main/java/com/bwie/service/BillManager.java b/src/main/java/com/bwie/service/BillManager.java new file mode 100644 index 0000000..dcd5213 --- /dev/null +++ b/src/main/java/com/bwie/service/BillManager.java @@ -0,0 +1,53 @@ +package com.bwie.service; +import com.bwie.dmain.Bill; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Lenovo + */ +public class BillManager { + + String URL="jdbc:mysql://129.211.0.187:3306/bill_table"; + String ROOT="root"; + String PASSWORD="wmw1234"; + + //添加方法 + public Boolean billAdd(double billMoney){ + try { + String billAdd="INSERT INTO bill VALUES (now(),?);"; + Connection connection = DriverManager.getConnection(URL,ROOT,PASSWORD); + PreparedStatement preparedStatement = connection.prepareStatement(billAdd); + preparedStatement.setDouble(1,billMoney); + + int i = preparedStatement.executeUpdate(); + return i > 0; + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + //查询方法 + public List selectAll(){ + ArrayList bills = new ArrayList<>(); + try { + Connection connection = DriverManager.getConnection(URL, ROOT, PASSWORD); + PreparedStatement preparedStatement = connection.prepareStatement("select * from bill"); + ResultSet resultSet = preparedStatement.executeQuery(); + Bill bill = new Bill(); + int id = resultSet.getInt(1); + Date billDate = resultSet.getDate(2); + double billMoney = resultSet.getDouble(3); + bill.setId(id); + bill.setBillDate(billDate); + bill.setBillMoney(billMoney); + bills.add(bill); + } catch (SQLException e) { + e.printStackTrace(); + } + return bills; + } + + +}