I want to make a SELECT method that can work regardless of table structures (different number of columns, data type and etc. I'm not asking for source code. I just need some advice, ideas, or directions as to how I can get there.
Here are my code : (which only works when I know the data type and number of columns in that table)
public static void select(Connection con, String USRIDX ) throws ClassNotFoundException {
String sql = "SELECT * from test where USRIDX =" + USRIDX;
try(PreparedStatement pstmt = con.prepareStatement(sql)) {
ResultSet rs = pstmt.executeQuery(sql);
while(rs.next()) {
String a = rs.getString(1);
String b = rs.getString(2);
String c = rs.getString(3);
LOG.info(a +" " + b + " "+c );
}
} catch(SQLException e) {
LOG.info(e.getMessage());
}
}