How to avoid overloading due to code duplication?

How to avoid overloading due to code duplication?

I am trying to insert the name,hashed password,salt and the hash type to the database. Only thing changing is the type of the parameters. I believe that it can be done more efficiently. How can I avoid using overloading? Do I need to use generics? Thank you.

I am trying to insert the name,hashed password,salt and the hash type to the database. Only thing changing is the type of the parameters. I believe that it can be done more efficiently. How can I avoid using overloading? Do I need to use generics? Thank you.

InsertMethods

protected void insert(String name, String secretpassword, String salt, String type)
{
    String sql = "INSERT INTO login(username,password,salt,type) VALUES(?,?,?,?)";

try (Connection conn = this.connect();
     PreparedStatement pstmt = conn.prepareStatement(sql)) {
    pstmt.setString(1, name);
    pstmt.setString(2, secretpassword);
    pstmt.setString(3, salt);
    pstmt.setString(4, type);
    pstmt.executeUpdate();
    System.out.println("Successful");
} catch (SQLException e) {
    System.out.println(e.getMessage());
}

}

protected void insert(String name, byte[] secretpassword, String salt, String type) { String sql = "INSERT INTO login(username,password,salt,type) VALUES(?,?,?,?)";

try (Connection conn = this.connect();
     PreparedStatement pstmt = conn.prepareStatement(sql)) {
    pstmt.setString(1, name);
    pstmt.setString(2, Arrays.toString(secretpassword));
    pstmt.setString(3, salt);
    pstmt.setString(4, type);
    pstmt.executeUpdate();
    System.out.println("Successful");
} catch (SQLException e) {
    System.out.println(e.getMessage());
}

}


java

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...

Java Multithreading Example | Multithreading in Java

Java Multithreading Tutorial With Example | Multithreading in Java. Multithreading is a process of executing multiple threads simultaneously.

Java File Class Tutorial | Java.io File Class in Java Example

Java File class represents the path of directories and files. It provides the methods for renaming, deleting, and obtaining the properties of file or directory.

Java Hashmap Example | HashMap in Java

Java HashMap is the part of Collections since JDK1.2. Java HashMap provides the underlying implementation of the Map interface of Java.