我正在尝试将名称、散列密码、盐和散列类型插入数据库。唯一改变的是参数的类型。我相信它可以更有效地完成。如何避免使用重载?我需要使用泛型吗?谢谢你。
插入方法
protected void insert(String name, String secretpassword, String salt, String type)
{
String sql = "INSERT INTO login(username,password,salt,type) VALUES(?,?,?,?)";
try (Connection conn = this.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, name);
pstmt.setString(2, secretpassword);
pstmt.setString(3, salt);
pstmt.setString(4, type);
pstmt.executeUpdate();
System.out.println("Successful");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
protected void insert(String name, byte[] secretpassword, String salt, String type)
{
String sql = "INSERT INTO login(username,password,salt,type) VALUES(?,?,?,?)";
try (Connection conn = this.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, name);
pstmt.setString(2, Arrays.toString(secretpassword));
pstmt.setString(3, salt);
pstmt.setString(4, type);
pstmt.executeUpdate();
System.out.println("Successful");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
明月笑刀无情
慕码人8056858
慕尼黑8549860
相关分类