1
 public void adduser(UserBean user) throws SQLException{
   String query = "INSERT INTO usersInformation ( username, " + 
     "password, email ) VALUES ( '" + user.getUsername() + "', '" + 
     user.getPassword() + "', '" + user.getEmail() + "' )" ;
   statement.execute(query);
}

I get this exception in this line : statement.execute(query) Can anyone helps me ? Exception : was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140525011235350' defined on 'USERSINFORMATION'.

[EDITED]

This is my bean class

public class UserBean {

private String username;
private String password;
private String email;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}
}

index.jsp ( Mail part of index.jsp )

<%@page contentType="text/html" pageEncoding="UTF-8"%>
 <jsp:useBean id = "userbean" class = "newpackage.UserBean"  />
 <jsp:useBean id = "userdatabean" class = "newpackage.UserDataBean" />

     <jsp:setProperty name ="userbean" property="*"/>
        <% userdatabean.adduser(userbean); %>
faraa
  • 575
  • 3
  • 14
  • 42
  • 1
    Not going to solve the current problem, but you're currently open to [SQL Injection](http://security.stackexchange.com/questions/25684/how-can-i-explain-sql-injection-without-technical-jargon) (depending on how account login/recovery is written, I can get you to email me the contents of your database). You need to be using [parameterized queries](http://stackoverflow.com/q/1812891), period. – Clockwork-Muse May 25 '14 at 05:39
  • Thank you so much . I am a beginner and these are my first SQL Code :) – faraa May 25 '14 at 06:04

1 Answers1

1

From the exception details it's clear that the statement is entering duplicate value in primary key field, thus violating unique key constraint. Check your data and insert accordingly

Abhinab Kanrar
  • 1,532
  • 2
  • 20
  • 46