I want to write a SpringBatch Tasklet, that automatically activates or de-activates all indexes for a given database table. The code needs to work independantly of the DBMS
The other way of getting all indexes is using the information_schema statistics table:
public void GetIndexesOfThisTable(final String tableName) {
try {
PreparedStatement ps = conn.prepareStatement("SELECT DISTINCT INDEX_NAME FROM information_schema.statistics WHERE table_name = ?");
ps.setString(1, tableName);
ResultSet rs = ps.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1));
}
rs.close();
ps.close();//important to close to prevent resource leaks
}
catch (Exception ex) {System.out.println(ex.getMessage());}
}