0414 复利计算再升级

本次更新有可以有

1.“这个数据我经常会填.....帮我预先填上呗?”

2.选择投资公司

3.输出总共金额

package fuli;
import java.sql.*;
public class mysql  {
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/test";
    static final String USER = "root";
    static final String PASS = "root";

    int i=1;
    double output(String gongsi,String putinto,String earnings,String year,String money) throws SQLException{
    	Connection conn = null;
        Statement stmt = null;
        
        //STEP 2: Register JDBC driver
        try {
			Class.forName(JDBC_DRIVER);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        //STEP 3: Open a connection
        conn = DriverManager.getConnection(DB_URL,USER,PASS);
        
        //STEP 4: Execute a query
        stmt = conn.createStatement();
        
        String sql;
        sql = "SELECT * FROM touzi";
        ResultSet rs = stmt.executeQuery(sql);
        
        int r=1;
        double sum=0;
        //STEP 5: Extract data from result set
          while(null != rs && rs.next()){
             System.out.println(rs.getString("putinto"));
             System.out.println(rs.getString("earnings"));
             System.out.println(rs.getString("number")); 
             
             System.out.println();
             r++;
             sum=Double.parseDouble(rs.getString("money"))+sum;
        }    
        
        String I = Integer.toString(i);
        String sql1 = "INSERT INTO touzi(number,gongsi,putinto,earnings,year,money) VALUES(";
        sql1=sql1+"'"+I+"'"+','+"'"+gongsi+"'"+','+"'"+putinto+"'"+','+"'"+earnings+"'"+','+"'"+year+"'"+','+"'"+money+"'"+')';
       
        i++;
       
        System.out.print(sql1);
        stmt.executeUpdate(sql1);
        
        rs.close();
        stmt.close();
        conn.close();
        return sum;
    }
	
	
    
   
}

  代码其实没有多大改动,只是增加了一些小小的功能;

 

 

 

发现了一个问题:在输入中文时出现了乱码现象,解决方法:http://blog.sina.com.cn/s/blog_691415940100yzut.html

github地址:https://github.com/ClearYellow/cooperation.git

转载于:https://www.cnblogs.com/wangjunjie123/p/5392596.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值