复利计算升级

合作伙伴:

学号:201406114252

姓名:王俊杰

博客地址:http://www.cnblogs.com/wangjunjie123/p/5392596.html

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

本次更新有可以有

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

总结:进行进一步改进对我们来说有点难度,但还是能更好地改进不足的地方。

posted @ 2016-04-14 20:43  50黄柏堂  阅读(335)  评论(6编辑  收藏  举报