作者:qq2304944703 | 来源:互联网 | 2023-05-19 16:01
Iamworkingonawebapplicationinwhichdatawillbetransferbetweenclient&serverside.
I am working on a web application in which data will be transfer between client & server side.
我正在开发一个web应用程序,其中的数据将在客户端和服务器端之间传输。
I already know that Javascript int != Java int. Because, Java int cannot be null, right. Now this is the problem I am facing.
我已经知道Javascript int != Java int.因为Java int不能为空。这就是我面临的问题。
I changed my Java int variables into Integer.
我将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();
}
My problem is here:
我的问题是:
pstmt.setInt(1, tempID);
pstmt.setInt(3, tage);
I cant use the Integer variables here. I tried with intgerObject.intValue();
But it makes things more complex. Do we have any other conversion methods or conversion techniques?
我不能在这里用整数变量。我试着与intgerObject.intValue();但这让事情变得更加复杂。我们还有其他的转换方法或转换技术吗?
Any fix would be better.
任何修复都会更好。
5 个解决方案