import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
class OperatiiBD {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
public void insert(String nume, int varsta, String nastere) {
String SQL = "insert into fairies (Name, Age, birthday) values ( ?, ?, ?)";
jdbcTemplateObject.update( SQL, nume, varsta, nastere);
}
public void update(int id, int varsta){
String SQL = "update fairies set Age = ? where id = ?";
jdbcTemplateObject.update(SQL, id, varsta);
}
public void delete(int id){
String SQL = "delete from fairies where id = ?";
jdbcTemplateObject.update(SQL, id);
}
public Winx getWinx(int id) {
String SQL = "select * from fairies where id = ?";
Winx winx = jdbcTemplateObject.queryForObject(SQL,new Object[]{id},
new Winxmapper());
return winx;
}
public List<Winx> getListaWinx() {
String SQL = "select * from fairies";
List <Winx> winx = jdbcTemplateObject.query(SQL,new Winxmapper());
return winx;
}
}