I have created a JSP page to register new users.In the registration form, there are 5 fields where the users enter their details.
After pressing the submit button they will be taken to another page where they have to fill another form which includes some other details of them. The data, the user enters in the first form is successfully inserted into the first table but, when they send the data in the second form it gives an error saying
"java.sql.SQLException: Field 'artist_id' doesn't have a default value".
Here the atrist_id
is the primary key of the first table and it is the foreign key of the second table. Following is the signup and artist_info
.
structures of the second table
try {
String address_1 = request.getParameter("address_1");
String address_2 = request.getParameter("address_2");
String city = request.getParameter("city");
String postal_code = request.getParameter("postal_code");
String phone_number = request.getParameter("phone_number");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/painter?autoReconnect=true&useSSL=false", "root", "");
Statement st = con.createStatement();
//st.executeUpdate("insert into signup(uid,fname,lname,email,password,country)values('"+firstName+"','"+lastName+"','"+email+"','"+password+"','"+country+"')");
st.executeUpdate("insert into artist_info(address_1,address_2,city,postal_code,phone_number)"
+ "values('" + address_1 + "','" + address_2 + "','" + city + "','" + postal_code + "','" + phone_number + "')");
How should I change this code to get the value of artist_id
into the foreign key(artist_id) of the second table.Thank you.