我现在在 JSP 中使用 JDBC 时遇到一些问题。我正在尝试将用户名/传递 ext 插入我的 MySQL 数据库。我没有收到任何错误或异常,但是也没有将任何内容插入到我的数据库中。以下是我的代码,任何帮助将不胜感激。
<%
String uname=request.getParameter("userName");
String pword=request.getParameter("passWord");
String fname=request.getParameter("firstName");
String lname=request.getParameter("lastName");
String email=request.getParameter("emailAddress");
%>
<%
try{
String dbURL = "jdbc:mysql:localhost:3306/assi1";
String user = "root";
String pwd = "password";
String driver = "com.mysql.jdbc.Driver";
String query = "USE Users"+"INSERT INTO User (UserName, UserPass, FirstName, LastName, EmailAddress) " +
"VALUES ('"+uname+"','"+pword+"','"+fname+"','"+lname+"','"+email+"')";
Class.forName(driver);
Connection conn = DriverManager.getConnection(dbURL, user, pwd);
Statement statement = conn.createStatement();
statement.executeUpdate(query);
out.println("Data is successfully inserted!");
}
catch(SQLException e){
for (Throwable t : e)
t.printStackTrace();
}
%>
数据库脚本在这里:
CREATE DATABASE Users;
use Users;
CREATE TABLE User (
UserID INT NOT NULL AUTO_INCREMENT,
UserName VARCHAR(20),
UserPass VARCHAR(20),
FirstName VARCHAR(30),
LastName VARCHAR(35),
EmailAddress VARCHAR(50),
PRIMARY KEY (UserID)
);