I have created different classes with it's variables and I'm trying to create a Java program that creates tables in a SQL database. The issue is that I don't know how to send a class as a parameter in a function.
I'm working on this function:
public void createTable (/*Class c ?*/) {
ArrayList<String> fields = new ArrayList<>();
for (Field f: c.class.getDeclaredFields()) {
fields.add(f.getName());
}
Statement statement;
statement = connection.createStatement(); //This part of the function wouldn't work. But let's focus on the question
statement.execute("insert into " + c.getSimpleName() + "(" + String.join(", ", fields) + ") values" etc...
}
Please note that the second part of the function where I want to insert data into SQL database would not work as it's not finished. But, how could I receive in this function different classes (with different variables obviously) and do the same for all of the classes? (create a list with the name of it's fields).