我正在开发一个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();
,但这使事情变得更加复杂。我们是否有其他转换方法或技术?
任何修复都会更好。