Joomla 3.9.x has a file public_html/libraries/classmap.php that contains all the old style Class names, and the new replacements. E.g.
JLoader::registerAlias('JFactory', '\\Joomla\\CMS\\Factory', '5.0');
JFactory is indeed deprecated. You can rewrite
// JFactory is deprecated
$db = JFactory::getDbo();
// Put at the top of your file
// Just remove the J
$db = Factory::getDbo();
btw: sometimes the factory class has already been loaded and then you can just use
$db = $this->getDbo();
What IDE do you use?
Some IDE software packages can help you finding the right classes.
I use PHPStorm (commercial software) together with CodeSniffer and the Joomla code standard. PHPStorm indicates all deprecated classes. When I click on CTRL + point the mouse on JFactory, my IDE gives a pop-up "alias JFactory of abstract class Factory". When I CTRL + click on JFactory, my IDE opens the classmap file with old/new Class names. To easily replace the JFactory with the new Factory name, I click on it, press ALT + ENTER and choose "Import Class", choose Joomla\CMS\Factory, and the correct Name Spacing is placed on top of my file.