如何将整数转换为整数?
我正在开发一个Web应用程序,其中数据将在客户端和服务器端之间传输。
我已经知道JavaScript int != Java int。因为,Java int 不能为 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();
任何修复都会更好。