public static String getShardKeyByDRDS(final JdbcTemplate jdbcTemplate, final String catalogName,
                                            final String schemaName, final String tableName) {
        try {
            return (String) jdbcTemplate.execute("show partitions from ?", new PreparedStatementCallback() {

                public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
                    DatabaseMetaData metaData = ps.getConnection().getMetaData();
                    // String sName = getIdentifierName(schemaName, metaData);
                    String convertTableName = tableName;
                    if (metaData.storesUpperCaseIdentifiers()) {
                        convertTableName = tableName.toUpperCase();
                    }
                    if (metaData.storesLowerCaseIdentifiers()) {
                        convertTableName = tableName.toLowerCase();
                    }
                    String tName = convertTableName;
                    ps.setString(1, tName);
                    ResultSet rs = ps.executeQuery();
                    String log = null;
                    if (rs.next()) {
                        log = rs.getString("KEYS");
                    }

                    rs.close();
                    return log;
                }
            });
        } catch (DataAccessException e) {
            // 兼容下oracle源库和目标库DRDS表名不一致的情况,识别一下表名不存在
            Throwable cause = e.getRootCause();
            if (cause instanceof SQLException) {
                // ER_NO_SUCH_TABLE
                if (((SQLException) cause).getErrorCode() == 1146) {
                    return null;
                }
            }

            throw e;
        }
    }
public static String getShardKeyByDRDS ( final JdbcTemplate jdbcTemplate , final String catalogName , final String schemaName , final String tableName ) { try { return ( String ) jdbcTemplate . execute ( "show partitions from ?" , new PreparedStatementCallback ( ) { public Object doInPreparedStatement ( PreparedStatement ps ) throws SQLException , DataAccessException { DatabaseMetaData metaData = ps . getConnection ( ) . getMetaData ( ) ; String convertTableName = tableName ; if ( metaData . storesUpperCaseIdentifiers ( ) ) { convertTableName = tableName . toUpperCase ( ) ; } if ( metaData . storesLowerCaseIdentifiers ( ) ) { convertTableName = tableName . toLowerCase ( ) ; } String tName = convertTableName ; ps . setString ( 1 , tName ) ; ResultSet rs = ps . executeQuery ( ) ; String log = null ; if ( rs . next ( ) ) { log = rs . getString ( "KEYS" ) ; } rs . close ( ) ; return log ; } } ) ; } catch ( DataAccessException e ) { Throwable cause = e . getRootCause ( ) ; if ( cause instanceof SQLException ) { if ( ( ( SQLException ) cause ) . getErrorCode ( ) == 1146 ) { return null ; } } throw e ; } }
获取DRDS下表的拆分字段, 返回格式为 id,name

@param dataSource
@param schemaName
@param tableName
@return