postgresql подключить к андроид проекту

Пишу приложение заметки.

Использую БД postgreSQL12.

Создал таблицы написал скрипты, запросы и сохранил в файл

note.sql

Далее я добавил этот файл в андроид студио проект в папку assets/note.sql.

Так же добавил файл app.properties

driver-class-name=org.postgresql.Driver
url=jdbc:postgresql://127.0.0.1:5432/note
username=******
password=********

Читаю файл для работы с бд

public void init() {
        Properties properties = new Properties();
        AssetManager assetManager = context.getAssets();
     try (InputStream in = assetManager.open("app.properties")) {
            properties.load(Objects.requireNonNull(in));
            Class.forName(properties.getProperty("driver-class-name"));
            cn =  DriverManager.getConnection(
                    properties.getProperty("url"),
                    properties.getProperty("username"),
                    properties.getProperty("password")
            );
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }

Но возникает ошибка не верного подключения бд

E/TestRunner: java.lang.IllegalStateException: org.postgresql.util.PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.



  Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 5432) from /127.0.0.1 (port 44676) after 9999ms: isConnected failed: ECONNREFUSED (Connection refused)

Подскажите, что делаю не так? Как работать с файлом .sql не удаленно(не используя серв.), а именно в с файлом, который храниться в самом приложении?


Ответы (0 шт):