I have a java method in a data mapper, to create a user in a MySQL database.
Whenever I test creating a user I get this error
Unknown column 'phone' in 'field list'
here is my java method
public static void createUser( User user ) throws
LoginSampleException {
try {
Connection con = Connector.connection();
String SQL = "INSERT INTO Users (email, password, phonenumber, post, adress, role) VALUES (?, ?, ?, ?, ?, ?)";
PreparedStatement ps = con.prepareStatement( SQL, Statement.RETURN_GENERATED_KEYS );
ps.setString( 1, user.getEmail() );
ps.setString( 2, user.getPassword() );
ps.setString( 3, user.getPhonenumber() );
ps.setInt( 4, user.getPostalCode() );
ps.setString( 5, user.getAddress() );
ps.setString( 6, user.getRole() );
ps.executeUpdate();
ResultSet ids = ps.getGeneratedKeys();
ids.next();
int id = ids.getInt( 1 );
user.setId( id );
} catch ( SQLException | ClassNotFoundException ex ) {
throw new LoginSampleException( ex.getMessage() );
}
}
It might be a syntax error, but I'm not sure why i get this error, I have double checked all fields to make sure that everything is typed correctly.
EDIT:
here is my SQL-script that creates the database:
CREATE TABLE `Users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`email` VARCHAR(90) NOT NULL,
`password` BLOB NOT NULL,
`phone` INT(16) NOT NULL,
`post` INT(8) NOT NULL,
`adress` VARCHAR(45) NOT NULL,
`role` VARCHAR(20) NOT NULL DEFAULT 'customer',
PRIMARY KEY (`id`),
UNIQUE KEY `email_UNIQUE` (`email`)
) ENGINE=INNODB AUTO_INCREMENT=4 DEFAULT CHARSET=LATIN1;