Skip to content

mjc-school/stage2-module6-jdbc-assignments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Database Connectivity assignment

    • You need to create a postgresql database called "myfirstdb" binding on port 5432.

    • The database should contain information about users:

      • unique identifier(Id),
      • user first name,
      • user last name
      • user age.

      (Table name - myusers, with the column: id, firstname, lastname, age)

    • For config datasource use app.properties file.

  1. Implement class CustomConnector to get connection with "myfirstdb" database.

public class CustomConnector {
    public Connection getConnection(String url) {
    }

    public Connection getConnection(String url, String user, String password)  {
    }
}
  1. Implement class CustomDataSource using singleton pattern to get connection with "myfirstdb" database:
@Getter
@Setter
public class CustomDataSource implements DataSource {
    private static volatile CustomDataSource instance;
    private final String driver;
    private final String url;
    private final String name;
    private final String password;
    //  code

    private CustomDataSource(String driver, String url, String password, String name) {
        //  code
    }


    public static CustomDataSource getInstance() {
        //  code
        return instance;
    }
//  code
    • Implement class SimpleJDBCRepository, resolve all class methods for create, update, delete and search Users.
    • Use CustomDataSource and CustomConnector for performing statement or prepareStatement to database.
public class SimpleJDBCRepository {

    private Connection connection = null;
    private PreparedStatement ps = null;
    private Statement st = null;

    private static final String createUserSQL = "";
    private static final String updateUserSQL = "";
    private static final String deleteUser = "";
    private static final String findUserByIdSQL = "";
    private static final String findUserByNameSQL = "";
    private static final String findAllUserSQL = "";

    public Long createUser() {
        //  code
    }

    public User findUserById(Long userId) {
        //  code
    }

    public User findUserByName(String userName) {
        //  code
    }

    public List<User> findAllUser() {
        //  code
    }

    public User updateUser() {
        //  code
    }

    private void deleteUser(Long userId) {
        //  code
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages