• 复利计算--结对2.0


    结对同伴:

      名字:蔡彩虹

      学号:201406114202

      博客地址:http://www.cnblogs.com/caicaihong/

    一、项目简介

      开发工具:Eclipse

      开发语言:java

      主要功能:复利计算、单利计算,分项投资

    二、新增功能——数据库存储和查询

        目的:为了更加方便顾客读写数据。

                除此之外,我们的界面也更加完善。

    三、分工:

      蓝叶:书写代码,构思数据库存储和查询方案

      蔡彩虹:测试代码,并把界面继续完善

    四、时间和代码量估算:

      估计:需要2小时,预计代码量为80行
      实际:用了1.5小时,新增代码82行
     

    五:主要代码:

    (1)界面:

    (2)主要代码(数据库存储和查询)

    private void SQL_Insert() throws SQLException {
    
            String url = "jdbc:mysql://localhost:3306/fuli";
            String user = "root";
            String pwd = "0000";
    
            Connection conn = null;
            Statement st = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(url, user, pwd);
                st = conn.createStatement();
    
                // 插入记录
                st.addBatch("insert into fuli values('" + project + "','" + P + "','" + R + "','" + N + "','" + F + "')");
    
                // 执行批处理
                st.executeBatch();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                    if (conn != null) {
                        conn.close();
                        conn = null;
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        
        private void SQL_Show() throws SQLException {
    
            String url = "jdbc:mysql://localhost:3306/fuli";
            String user = "root";
            String pwd = "0000";
    
            Connection conn = null;
            Statement st = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(url, user, pwd);
                st = conn.createStatement();
    
                // 查看表
                String sql = "select * from fuli";    //要执行的SQL
                ResultSet rs = st.executeQuery(sql);// 创建数据对象
                jTextArea0.setText(null);
                while (rs.next()) {
                    jTextArea0.append(rs.getString(1) + "	");
                    jTextArea0.append(rs.getString(2) + "	");
                    jTextArea0.append(rs.getString(3) + "	");
                    jTextArea0.append(rs.getString(4) + "	");
                    jTextArea0.append(rs.getString(5) + "	");
                    jTextArea0.append("
    ");
                }
                
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (st != null) {
                        st.close();
                        st = null;
                    }
                    if (conn != null) {
                        conn.close();
                        conn = null;
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    (3)结果:

    输入数据,存到数据库

    数据这时就能存进数据库中的表了

    查看已投资项目(查看数据库中的表并显示到文本区域中) 

    全部代码以上传github:https://github.com/LanLeaf/Lan-work/blob/master/fuli_6.java

  • 相关阅读:
    第一篇阅读笔记
    课程信息管理系统
    HDU1124求n的阶乘后0的个数
    分解质因数算法
    牛客小白月赛23 B阶乘(质因数分解)
    JAVAWEB将图片铺满整个页面的方法
    Codeforces Global Round 7
    POJ--1703并查集(区分两个集合)
    POJ--1611经典并查集
    DFS,BFS回顾(各种题)(肺炎疫情中,祝平安)
  • 原文地址:https://www.cnblogs.com/blueYE00/p/5393375.html
Copyright © 2020-2023  润新知