package test1jdbc;

import java.sql.*;

public class TestJdbcOdbc
{
    public static void main (String[] args)
    {
        Connection conn = null;
        Statement stm = null;
        String db = "jdbc:odbc:kontakty";
        String query = "SELECT * FROM [osoba$], [adres$], [telefon$] WHERE [osoba$].id=[adres$].id AND [osoba$].id=[telefon$].id";
        System.out.println("--- początek ---");
        try
        {
            conn = DriverManager.getConnection(db);
            stm = conn.createStatement();
            ResultSet rs = stm.executeQuery(query);
            
            while (rs.next())
            {
                String im = rs.getString("imie");
                String naz = rs.getString("nazwisko");
                String pl = rs.getString("plec");
                double wzr = rs.getDouble("wzrost");
                int waga = rs.getInt("waga");
                Date ur = rs.getDate("data_ur");
                String adr = rs.getString("adres");
                String tel = rs.getString("telefon");
                System.out.println(im+" "+naz+(pl.charAt(0)=='m'?" (mężczyzna) ur: ":" (kobieta) ur: ")+ur+" / wzrost = "+wzr+" / waga = "+waga+" /// adres: "+adr+" /// telefon: "+tel);
            }
        }
        catch (SQLException ex)
        {
            do
            {
                System.err.println(ex.getMessage());
            }
            while ((ex=ex.getNextException())!=null);
        }
        finally
        {
            try { if (stm != null) stm.close(); } catch (Exception ex) {}
            try { if (conn != null) conn.close(); } catch (Exception ex) {}
        }
        System.out.println("---- koniec ----");
    }
}
