Good day! I try to localize all the functions associated with working with the database in the same class. For example, I try to write a function that, at the input, receives a string with the query text, and returns the result.
public Map ReadToMySQL(String query) { try { // opening database connection to MySQL server con = DriverManager.getConnection(url, user, password); // getting Statement object to execute query stmt = con.createStatement(); // executing SELECT query rs = stmt.executeQuery(query); while (rs.next()) { int count = rs.getInt(1); .... } } catch (SQLException sqlEx) { sqlEx.printStackTrace(); } finally { //close connection ,stmt and resultset here try { con.close(); } catch(SQLException se) { /*can't do anything */ } try { stmt.close(); } catch(SQLException se) { /*can't do anything */ } try { rs.close(); } catch(SQLException se) { /*can't do anything */ } } return ....; } The question is, what should such a function return? It is assumed that the query to the database can be anything: return a different number of variables and variables of different types. I really do not want to write for each request my own function of reading from the database. Maybe there is some standard class architecture for working with the database?
