Как подключить postgresql intellij idea

от admin

PostgreSQL

In the Database tool window ( View | Tool Windows | Database ), click the Data Source Properties icon .

On the Data Sources tab in the Data Sources and Drivers dialog, click the Add icon () and select PostgreSQL .

Check if there is a Download missing driver files link at the bottom of the data source settings area. As you click this link, IntelliJ IDEA downloads drivers that are required to interact with a database. The IDE does not include bundled drivers in order to have a smaller size of the installation package and to keep driver versions up-to-date for each IDE version.

You can specify your drivers for the data source if you do not want to download the provided drivers. For more information about creating a database connection with your driver, see Add a user driver to an existing connection.

From the Authentication list, select an authentication method.

pgpass : by using the PGPASS file. You can store this file in the user’s home directory (for example, /Users/jetbrains/.pgpass ). You can read more about the password file in The Password File at postgresql.org.

User & Password : by using your login and password.

Specify database connection details. Alternatively, paste the JDBC URL in the URL field.

To delete a password, right-click the Password field and select Set Empty .

To ensure that the connection to the data source is successful, click the Test Connection link.

How to setup Intellij and create your first JDBC Project (Mac andWindows)

Alternative, you could use Eclipse Enterprise edition, it’s free.

2.Postgres Database or any Database of your choice, I’ll be proceeding this tutorial with postgres. However, the procedure to setup any database is almost similar.

Step: -1 Download the postgres file and install it, once you installed it on mac

In the top-right corner, you’ll see an icon of elephant, click on it and click on Open Postgres.

Once, you clicked on it, you’ll see a window like this. You can see the green tick mark saying running. That means everything is working fine and your postgres server is up and running.

Here, a container named postgres is a root user and corresponding that user a “postgres” named database is by default created for us. As we’ll not get much into its details as it is not an integral part of this project.

Step: -2 Now Open your installed IntelliJ and Create a new Project as shown below in the pictures.

Click on New project

Click on Gradle (Build tool) and then Select java and proceed to next

Give a name to your project and click on finish. It’ll take a while to setup and configure your project completely. Once it’s finished your project will look like this in picture below.

Click on “src” directory, then main, then java

Now, you’ll see “com.jdbc.project” this is the package where we’ll be working on throughout this project.

implementation group: ‘org.postgresql’, name: ‘postgresql’, version: ‘42.2.18’

First, put this text inside build.gradle file under dependency section and build your project then proceed ahead with the pictures shown below.

Now we’ll connect our Database to our IDE.

Click on view, and then proceed ahead with the pictures shown below.

You’ll see a new tab appears on the left-side of your IDE, now at this point you must be thinking what’s this “hplusposrt@localhost”, It’s my database that I have connected to already. In your case there’ll be “postgres@localhost” written on your window as we’ll be using the default database.

Let’s hit to the + icon.

Then proceed ahead with pictures shown below, in this case we are selecting postgres, as we are using postgres database, if you prefer to use any other database like MySQL, Oracle etc, you’d select that.

Once you clicked on it, a new screen will appear.Fill each field as it is filled in the picture shown blown and click on apply and press ok.In Case, it’ll pop-up an error showing a message that “driver is not installed”, click on it and installed the driver and resume the process. Make sure you test the connection before clicking on apply and ok.

Once you’ll click on apply and then Ok, a new console will appear like thisWith named “postgres@localhost”. This is the console where you can write ‘SQL’ queries in order to create a table and any operation, you wanna perform on a database.

Remember this play button, it’ll help you to execute your queries.Now we’ll execute this query to create a table named “customer” and fill that table with some data. Paste this code into this console and hit the play button.

Now, we have our data inserted into the table, we can now work on to performing CRUD operations on it. (Create, Read, Update and Delete)

First, we will create some classes and interface in the root package.First, Right-click on “com.jdbc.project” and create a new package named “util”, under util create one class named “DataAccessObject” and one interface named “DataTransferObject”.

DataAccessObject class is an abstract class which we will inherit in the CustomerDAO.class and implement all the methods defined inside it.It helps us to provide an abstraction layer over our whole project.

DataTransferObject.class is helper class of DataAccessObject , we could have achieved the same result by defining this getId() function in our Customer.class.

Then again, Right-click on root package and create four classes name shown in the picture above.

Customer.class is our model, a type of data-model, we have previously inserted in our database, so when we fetch any data from database, we could store it in some kind of object and show it to user or if we insert some data, we could insert it via a object.

CustomerDAO.class is our class that extends our DataAccessObject.class and implements its all declared method and define it according its use. For the sake of following Java’s Abstraction and Encapsulation Principle, we have taken this approach, we could have declared and defined all our functions in CustomerDAO.class itself instead of overriding it.

We have our Database operation codes are in good place, but we forgot the most important thing to do. creating a connection to database with our code.DataBaseConnectionManager.class will help us do that.

JDBCExecutor.class, this is the class where your main() function resides and get invoked when you first run the program.In your case it might have a different name, you can refractor it if you want.

As you can see I have commented out some code in it, you can uncomment it and run the code for any specific CRUD operation. After performing any operation, for cross-checking refer to console where you have first-time written your SQL query and execute query , just to become sure that your code is working or Not!

and that brings us to an end, thank you for reading and if you liked it, you can clap for it.

Читать:
Network icontrol что это

Как подключить postgresql intellij idea

In the Database tool window ( View | Tool Windows | Database ), click the Data Source Properties icon .

On the Data Sources tab in the Data Sources and Drivers dialog, click the Add icon () and select PostgreSQL .

At the bottom of the data source settings area, click the Download missing driver files link. As you click this link, IntelliJ IDEA downloads drivers that are required to interact with a database. The IDE does not include bundled drivers in order to have a smaller size of the installation package and to keep driver versions up-to-date for each IDE version.

You can specify your drivers for the data source if you do not want to download the provided drivers. For more information about creating a database connection with your driver, see Add a user driver to an existing connection.

From the Authentication list, select an authentication method.

pgpass : by using the PGPASS file. You can store this file in the user’s home directory (for example, /Users/jetbrains/.pgpass ). You can read more about the password file in The Password File at postgresql.org.

User & Password : by using your login and password.

Specify database connection details. Alternatively, paste the JDBC URL in the URL field.

To delete a password, right-click the Password field and select Set Empty .

To ensure that the connection to the data source is successful, click the Test Connection link.

Русские Блоги

2. Щелкните знак плюса, выберите Источник данных и выберите базу данных PostgreSQL во всплывающих окнах.

3. Ввод информации

Хост: если это локальная база данных, введите localhost напрямую, в противном случае введите IP-адрес базы данных.

Пользователь: имя пользователя

После завершения ввода нажмите «Проверить соединение», чтобы убедиться, что соединение установлено. На приведенном выше рисунке показано, что соединение установлено успешно, поскольку на рисунке показано «Успешно»

Интеллектуальная рекомендация

Использование Mybatis paging assistant и General Mapper

Трансфер изhttps://blog.csdn.net/zbw18297786698/article/details/53945729/ 1. Представление Mybatis paging assistant 2. Использование Mybatis paging assistant 3. В программе Java установите параметры п.

64-битная целочисленная проблема

Название Описание Введите положительное целое число n, посчитайте количество его положительных множителей, n <= 10 ^ (12), например, когда n = 30, на выходе должно быть 8. Исходный код Анатомия Лог.

Кратко поговорим о шаблонах проектирования-мост

1. Что такое режим моста Режим моста (Bridge) отделяет абстрактную часть от части реализации, так что все они могут быть изменены независимо. Схема структуры UML выглядит следующим образом: Среди них .

Простое приложение Android Android (1)

Простое приложение Android Android (1) Во-первых, кратко Помните, — я не узнал простое приложение Android. (Операция дизайна учебной программы) Пример Пакет: Ссылка: https: //pan.baidu.com/s/1leq1owku.

Формат вывода строк Python

# В основном используют способ форматирования строки для вывода, в общем, строка в формате вывода.

Похожие статьи