Skip to content

🗃️ ✏️ PostgreSQL + hibernate. CRUD operations.

Notifications You must be signed in to change notification settings

bbogdasha/postgresqlCRUD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgresql CRUD operations

Working with the Postgresql database and basic functions Create + Read + Update + Delete (CRUD). Functions are performed through SQL requests. For communication between the database and Java classes, the technology is used Hibernate.

Task

Implement an interface with methods:

  • void removeAll()

  • void removeUser(int id)

  • void removeUserByName(String name)

  • void addUser(User user)

  • void updateUser(User user)

  • User getUser(int id)

  • List getAllUsers()

Tech

  • Postgresql;
  • Hibernate;
  • SQL.

Result

1. (C) After creating the users table in the database itself using the SCL command Script, the first step is to create new users in the database:

        userDao.addUser(new User("Bob",24));
        userDao.addUser(new User("Masha",26));
        userDao.addUser(new User("Tommy",19));
        userDao.addUser(new User("Alex",18));
        userDao.addUser(new User("Viki",22));
        userDao.addUser(new User("Ana",27));
        userDao.addUser(new User("Alex",33));
        userDao.addUser(new User("Poul",41));

Result in database:

Screenshot


2. (R) The second action is the output of information requested for different parameters (id, name, all).

        userDao.getUserById(2);
        userDao.getUserByName("Alex");
        userDao.getAllUsers();

Result:

Screenshot


3. (U) Third step - updating user data.

        User user = userDao.getUserById(2);
        user.setAge(37);
        user.setName("Moa");
        userDao.updateUser(user);
        userDao.getUserById(2);

Result:

Screenshot


4. (D) And the last operation to delete users with different parameters (id, name, all).

        userDao.removeUserById(2);
        userDao.removeUserByName("Alex");

Result:

Screenshot

In the end, after all the operations CRUD with the database, we will get the following result:

Screenshot

About

🗃️ ✏️ PostgreSQL + hibernate. CRUD operations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages