My first post here so go easy on me :).
So I created a database table using the following code.(Im using Oracle 10g and Oracle JDBC. Im having this servlet code communicate with a HTML form I made.)
CREATE TABLE GM_Recipes
(
recipe_ID NUMBER(4) PRIMARY KEY,
rec_name VARCHAR2(50),
recipe_cat VARCHAR2(50),
rec_desc VARCHAR2(1000),
author VARCHAR2(50)
);
Now my servlet code is as such:
// Fill Recipes table
PreparedStatement pstmt = con.prepareStatement("INSERT INTO GM_Recipes(rec_name,recipe_cat,rec_desc,author) VALUES (?,?,?,?)");
pstmt.clearParameters();
String opt1 = req.getParameter("RecName"); //parameters from HTML form
String opt2 = req.getParameter("choice"); //parameters from HTML form
String opt3 = req.getParameter("CookDesc"); //parameters from HTML form
String opt4 = req.getParameter("author"); //parameters from HTML form
pstmt.setString(1,opt1);
pstmt.setString(2,opt2);
pstmt.setString(3,opt3);
pstmt.setString(4,opt4);
ResultSet rs = pstmt.executeQuery();
What Id like to do is insert a row into the GM_Recipes table but have the recipe_ID be auto generated.(As through a HTML form I won't ask someone to enter a recipe ID for obvious reasons)
Later parts of my code are reliant on a recipe_ID for new recipes that would be created.
Ive tried some generate keys code that I found from google but I've been at it for a few hours and was curious if anyone could share some meaningful insight :) Thanks