I have created a method (getData()
) to receive data from the database which seems to work. What I want is to use only 1 parameter, so the method should run with className.getData("SELECT * FROM myTable")
. How can I do this?
public List<String> getData(String sql, Map column) {
this.driver();
try {
Connection conn = DriverManager.getConnection(this.url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
List<String> result = new ArrayList<>();
if (column.containsKey("string")) {
for (Object i : column.values()) {
while (rs.next()) {
result.add(rs.getString(String.valueOf(i)));
}
}
return result;
}
}
catch (SQLException e) {
e.printStackTrace();
}
return null;
}
private void driver() {
// Ensure we have mariadb Driver in classpath
try {
Class.forName("org.mariadb.jdbc.Driver");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
>` or some other 2D structure?