Click here to Skip to main content
15,670,097 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to add the data to the database which the user inputs from the form, it only adds the one which is specified in the film object. I'm not sure what the problem is here, can someone help please.

What I have tried:

I have sorted out the form and url and also called the java file. I have also created film object ad called the insertFilm method which adds the data to the database. It's only adding the one in the film object and not the one which has been inserted in the form.

The film object which it keeps adding to the database:
Film f = new Film(123456, "Wars", 2011, "Peter Jackson","100", "5 ");


This is the film object which it keeps adding to the database. I don't want this being added, I would like the one added in the form.


Create-film.java file:
	// Creating protected void doGet to print out the list of films on tbe browser
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		PrintWriter out = response.getWriter();
		// Creating new film dao and calling the FilmDAO class
		// it asks the dao and then prints out the list of films
		FilmDAO film = new FilmDAO();

		// Getting all films from the array list
		ArrayList<Film> FilmList = FilmDAO.getAllFilms();	
		// Creating form loop for one film and then printing out the film
		for (int i=0; i<FilmList.size(); i++ ) {
			// Get film
			Film oneFilm = FilmList.get(i);
			// Print films out onto the console
			System.out.println(oneFilm.toString());
			System.out.println("All data displayed successfully");
		} // Close for loop



		// creating the, insert and calling the method from the dao class
		// insert film to the datbase
		// Calling the film class and inserting the film to the database. 
		System.out.println("Testing the insert film");
//		Film f = new Film(123456, "Wars", 2011, "Peter Jackson","100", "5 ");
		Film f = new Film(123456, "Wars", 2011, "Peter Jackson","100", "5 ");
		try {
			FilmDAO.insertFilm(f);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("DEBUG: Film Successfully inserted");




Html file:
<!DOCTYPE html>
<html>
<head>
<!--- Creating a heading for the form to create new film in the application -->
<h1>INSERT A FILM</h1>
<title>Form to create a new film</title>
<link rel="stylesheet" href="css/styles.css" type="text/css" />
</head>
<body>
	<form action="ControlInsertFilm" method="POST">
		<label for="id">ID</label> <input name="id" /> <br /> <label
			for="title">title</label> <input name="title" /> <br /> <label
			for="year">year</label> <input name="year" /> <br /> <label
			for="director">director</label> <input name="director" /> <br /> <label
			for="stars">stars</label> <input name="stars" /> <br /> <label
			for="review">review</label> <input name="review" /> <br /> <input
			type="submit" value="Submit" />
	</form>
</body>
</html>
Posted
Updated 16-Dec-18 9:50am
Comments
Richard MacCutchan 17-Dec-18 4:59am    
Your code never tries to insert the data sent from the webform, but only the predefined values.
Dhanyaal 17-Dec-18 6:27am    
If I wanted to insert the form ones into the database how can I do that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900