Is the "www" in the database for the site confguration?
No its not there in database.

It depends on global $base_url variable. 

How drupal define this variable is based on super global $_SERVER['HOST'] variable, which is basically depends on how the request was sent with/without www.

But you can override global $base_url in your settings.php
$base_url = 'http://yoursite.com'