Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JSP (http://www.go4expert.com/forums/jsp/)
-   -   JDBC - Insert Issue (http://www.go4expert.com/forums/jdbc-insert-issue-t28900/)

StrykeRXL 17Aug2012 06:59

JDBC - Insert Issue
 
Hi everyone. I am new and a new student to programming. 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.

Code:

    <%@page import="java.sql.*, java.util.*, javax.servlet.*, java.io.*, javax.servlet.http.*"%>
<%
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!");
        conn.close();
        }
        catch(SQLException e){
        for (Throwable t : e)
            t.printStackTrace();
        }
          %>


StrykeRXL 17Aug2012 07:03

Re: JDBC - Insert Issue
 
Sorry, I would like to add also my DB Script.

Code:

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)
);



All times are GMT +5.5. The time now is 09:58.