我的工作在一个网络应用程序,其中数据将传输之间的客户端和服务器端。
我已经知道 JavaScriptint! = Javaint。因为,Javaint 不能为 null,对吧。 这就是我现在面临的问题。
我把 Java int 变量改成了 Integer。
public void aouEmployee(Employee employee) throws SQLException, ClassNotFoundException
{
Integer tempID = employee.getId();
String tname = employee.getName();
Integer tage = employee.getAge();
String tdept = employee.getDept();
PreparedStatement pstmt;
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/general";
java.sql.Connection con = DriverManager.getConnection(url,"root", "1234");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
pstmt = (PreparedStatement) con.prepareStatement("REPLACE INTO PERSON SET ID=?, NAME=?, AGE=?, DEPT=?");
pstmt.setInt(1, tempID);
pstmt.setString(2, tname);
pstmt.setInt(3, tage);
pstmt.setString(4, tdept);
pstmt.executeUpdate();
}
我的问题是:
pstmt.setInt(1, tempID);
pstmt.setInt(3, tage);
我不能在这里使用整数变量。我试过使用 intgerObject.intValue();
但是它使事情变得更加复杂。我们还有其他的 < strong > 转换方法或转换技术吗?
任何补救措施都会更好。