Results 1 to 4 of 4
  1. #1
    eclectica is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Insert In SpringMVC

    Hi I have a Webapp and i want to insert a record in my db
    This is my controller

    Java Code:
    public class ReservationController {
    	@Autowired
    	private RoomDAO roomdao;
    	@Autowired
    	private ReservationDAO reservationdao;
    	
    	@RequestMapping(value={"/newReservation"},method=RequestMethod.GET)
        public String ReservationFormulier(ModelMap model){
            Reservation reservation = new Reservation();
            model.addAttribute("dereservatie", reservation);
            return "/newReservation";
        }
    	
    	@RequestMapping(value={"/newReservation"},method=RequestMethod.POST)
        public String ReservationMaken2(@ModelAttribute("dereservatie") @Valid Reservation reservation,
                                                            BindingResult result, ModelMap model){
    
    
    
            reservationdao.saveReservation(reservation.getRoomId(),reservation.getFirstname(),
            		reservation.getLastname(),reservation.getArrival(),reservation.getDeparture(),reservation.getNumberOfNights(),reservation.getNumberOfPersons(),reservation.getPrice());
            return "home";
        }
    }
    tis is my dao
    Java Code:
    Code:
    
    public interface ReservationDAO 
    {
    	public Reservation saveReservation(int roomId, String firstname, String lastname, String arrival, String departure,String numNights,String numPersons,double price);
    
    }

    my daoImpl

    Code:
    Java Code:
    public class ReservationDAOcoll implements ReservationDAO{
    	
    	@PersistenceContext
    	private EntityManager em;
    	
    	@Override
    	public Reservation saveReservation(int roomId, String firstname,
    			String lastname, String arrival, String departure,
    			String numNights, String numPersons, double price) {
    
    		Reservation reservation = new Reservation();
    		reservation.setRoomId(roomId);
    		reservation.setFirstname(firstname);
    		reservation.setLastname(lastname);
    		reservation.setArrival(arrival);
    		reservation.setDeparture(departure);
    		reservation.setNumberOfNights(numNights);
    		reservation.setNumberOfPersons(numPersons);
    		reservation.setPrice(price);
    		
    		em.persist(reservation);
    		return null;
    	}
    	
    	
    }
    When I press on save in my view it doensn't insert a new record in my db

    I have no errors, the webpage goes back to my home.jsp...

    Someone who knows what im doing wrong ?

    thnx!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: Insert In SpringMVC

    You'll need to stick some logs in there then and see exactly where in the code it is going wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    eclectica is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Insert In SpringMVC

    What do you mean?
    In my logs I have no warnings or errors
    He ignores my method
    reservationdao.saveReservation(reservation.getRoom Id(),reservation.getFirstname(),
    reservation.getLastname(),reservation.getArrival() ,reservation.getDeparture(),reservation.getNumberO fNights(),...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: Insert In SpringMVC

    I see no debug logging at all in the controller, so how do you know the controller is being called?
    I see no debug logging in saveReservation, so how do you know that method isn't being called?

    So stick some logging in those methods so you can see what (if anything) is going on in them, otherwise you are simply guessing.

    The other option is to debug it and step through.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. insert a row into the DB
    By miko5054 in forum JDBC
    Replies: 13
    Last Post: 07-11-2010, 02:01 PM
  2. How to insert '{'
    By izrydka in forum New To Java
    Replies: 3
    Last Post: 05-18-2010, 08:38 PM
  3. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  4. Help with sql insert
    By jmorris in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 07:05 PM
  5. SQL Insert Help!!!!
    By shaungoater in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •