How to use object manager magento2 to use table?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('my_table'); // the table name in this example is 'my_table'
$sql1 = "SELECT * FROM " . $tableName;
$result1 = $connection->fetchAll($sql1);
echo '<pre>'; print_r($result1); echo '</pre>'