package net.sevecek.select;

import java.sql.*;
import java.util.*;
import org.mariadb.jdbc.*;
import org.springframework.jdbc.core.*;

public class SpousteciTrida {

    public static void main(String[] args) throws Exception {
        MariaDbDataSource dataSource;
        dataSource = new MariaDbDataSource();
        dataSource.setUrl("jdbc:mysql://localhost/DailyPlanet");
        dataSource.setUser("student");
        dataSource.setPassword("password");

        JdbcTemplate pokladacDotazu;
        pokladacDotazu = new JdbcTemplate(dataSource);

        RowMapper<Autor> prevodnikTridyAutor;
        prevodnikTridyAutor = BeanPropertyRowMapper.newInstance(Autor.class);

        List<Autor> autori = pokladacDotazu.query(
                "select Autor_ID as id, KrestniJmeno, Prijmeni, Email, Telefon from autor",
                prevodnikTridyAutor);
        System.out.println("Autori v DB:");
        for (Autor jedenAutor : autori) {
            System.out.println(jedenAutor);
        }
    }

}
