I am having some issues right now with JDBC in JSP. I am trying to insert username/pass ext into my MySQL DB. I am not getting any error or exception, however nothing is being inserted into my DB either. Below is my code, any help would be greatly appreciated.
<%
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();
}
%>
DB script here:
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)
);