运行此代码时出现错误。我不知道为什么。我只想做一个方法,当被调用时会将数据存储在 MySQL 数据库中。这是代码:
public Employee(String firstName, String lastName,
String userID, String userPassword, String role)
{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hotelmanagementsystem", "some_user","");
PreparedStatement statement = con.prepareStatement("Insert into employee(Firstname, Lastname, UserID, UserPassword, Role)values(?, ?, ?, ?, ?");
statement.setString(1, firstName);
statement.setString(2, lastName);
statement.setString(3, userID);
statement.setString(4, userPassword);
statement.setString(5, role);
statement.executeUpdate();
con.close();
}
catch( Exception e ) {
e.printStackTrace();
return;
}
}
控制台:语法错误