Giter Site home page Giter Site logo

stage2-module6-jdbc-assignments's Introduction

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
    }
}

stage2-module6-jdbc-assignments's People

Contributors

sultaaann avatar antonazzot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.