Retrieve all Indexes for a given Table with JDBC

前端 未结 4 1343
臣服心动
臣服心动 2021-01-19 21:29

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

4条回答
  •  悲&欢浪女
    2021-01-19 21:38

    Below code is used to retrieve the INDEX_NAME From the DATABASE.

    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Main {
        public static void main(String[] args) throws Exception {
            Connection conn = getOracleConnection();  //Based on the database corresponding method should be called
            List schemaList=new ArrayList();
            List catalogList=new ArrayList();
            List indexs=new ArrayList();
            String dbIndexName=null;
            ResultSet rs=null;
            System.out.println("Got Connection.");
            try {
                DatabaseMetaData metaData = conn.getMetaData();
    
                ResultSet schemas = metaData.getSchemas();
                ResultSet catalog = metaData.getCatalogs();
                while (schemas.next()) {
                    String tableSchema = schemas.getString(1);  
                    schemaList.add(tableSchema);
                }
                while (catalog.next()) {
                    String allCatalog = catalog.getString(1);  
                    catalogList.add(allCatalog);
                }
    
    
                for(int i=0;i

    }

提交回复
热议问题