package com.sourcefellows.dependency;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class ShipService {
    public void storeShip(Ship ship) {
        DataSource dataSource;
        try {
            Context context = new InitialContext();
            dataSource = (DataSource) context.lookup("database_connection");
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
        try {
            Connection connection = dataSource.getConnection();
            //...
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
