0
下面是簡單的登錄系統。目前,它將允許我輸入一個空白的用戶名和密碼,即使每個索引被指定爲NOT NULL,也可以放入表中。它不會允許我輸入我想要的重複項,但是如何從輸入中捕獲空白參數?我錯過了什麼?JBDC和MYSQL空值插入表
註冊的Servlet
....
LoginService loginService = new LoginService();
connection = loginService.getConnection(connection);
loginService.addNewUser(preparedStatement, connection, newUserId, newUserPassword, newUserFirstName, newUserLastName);
...
login服務的方法AddNewUser函數
public void addNewUser(PreparedStatement ps, Connection connection, String newUserId, String newUserPassword,String newUserFirstName,String newUserLastname) throws SQLException
{
ps = connection.prepareStatement("INSERT INTO users (userId ,password , userFirstName, userLastName)VALUES(?,?,?,?)");
ps.setString(1, newUserId);
ps.setString(2, newUserPassword);
ps.setString(3, newUserFirstName);
ps.setString(4, newUserLastname);
ps.executeUpdate();
}
它是空白還是實際爲NULL? –
對不起,它是空白的,這是不是被認爲是同一件事? – Calgar99
不是,有些數據庫認爲空白等價於NULL(例如Oracle),但SQL標準和大多數數據庫認爲空白不同於任何其他值(包括空格)。另請參閱http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html –