标签:
本次更新有可以有
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
标签:
原文地址:http://www.cnblogs.com/wangjunjie123/p/5392596.html