0

How do I perform an insert query using jdbctemplate?

public void save(Student student) {
        jdbcTemplate.update("{call addStudent(default,?,?,?)}", student.getName(), student.getSurname(),student.getIdGroup());
    }

create procedure addStudent(IN name varchar(60), surname varchar(60), idGroup int)
BEGIN
    INSERT into student(id, name, surname, idGroup)
    VALUES (default , name, surname, idGroup);
end;
Justin
  • 1,972
  • 13
  • 28
Adamson
  • 1
  • 1

1 Answers1

0
CREATE PROCEDURE dbo.addStudent
@id varchar(32),@name varchar(60),@surname varchar(60),@idGroup int    AS    
BEGIN     SET NOCOUNT ON;    
INSERT into student(id, name, surname, idGroup)     VALUES (@id, @name, 
@surname, @idGroup);     
END

public void save(Student student) {    
long uuid = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;    
String uniqueID = Long.toString(uuid);    
String sqlQuery="EXECUTE addStudent @id,=?,@name=?,@surname =?,@idGroup =?";    
this.getJdbcTemplate().queryForRowSet(sqlQuery,uniqueID 
,student.getName(),student.getSurname(),student.getIdGroup());    
}  
Ume Habiba
  • 11
  • 3
  • Could you add more detail about this answer? Describe how you came to this conclusion with further details, such as citations or documentation, which helps other SO users confirm you answer is correct. Look at [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) for help. Also, try reformatting your code blocks. See [How to format code](https://stackoverflow.com/help/formatting). I would suggest using three backticks (```) or tildes (~~~) to make the code more readable. – charlie-map Mar 13 '22 at 20:54