我正在使用以下代码插入数据库,它工作正常,因为我可以看到数据填充在数据库中,但是我想以编程方式捕获结果,无论它是成功还是失败
1)这是要插入的代码
public void SignUp(String last_name, String first_name, String email,
String password, String confirm_password, String phone) {
Connect connect = new Connect();
Connection conn = connect.Connection();
Statement stmt = conn.createStatement();
String query = "INSERT INTO users VALUES(NULL,('" + last_name + "'),('"
+ first_name + "'),('" + email + "'),('" + password + "'),('"
+ confirm_password + "'),('" + phone + "'))";
stmt.executeUpdate(query);
conn.close();
}
2)这是我用来连接的代码
public Connection Connection() {
Connection conn = null;
try {
String userName = "admin";
String password = "admin";
String url = "jdbc:mysql://localhost/project";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("\n Database connection established");
} catch (Exception e) {
e.printStackTrace();
System.err.println("\n Cannot connect to database server");
}
}