空指针异常
package JDBC;import java.sql.*;
public class JDBCWH1 {
public static void main(String args []) throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","19821227");
Statement stmt=con.createStatement();
String sql="select id,total,sum from s_item where id='01';";
ResultSet rs=stmt.executeQuery(sql);
Integer total1=0;
while(rs.next()){
String id=rs.getString("id");
String total=rs.getString("total");
String sum=rs.getString("sum");
total1=Integer.getInteger(total); 空指针异常
// int sum1=Integer.getInteger(rs.getString("sum"));
total1*=2;
// sum1*=2;
Statement stmt1=con.createStatement();
String sql1="update s_item set sum="+sum+",total="+total1;
stmt1.executeUpdate(sql1);
}
con.close();
stmt.close();
rs.close();
}
}