Can a database serve two different installations on localhost?
There is no problem using a single database to serve multiple applications (including multiple Drupal instances).  However, they need to be completely separate instances. You cannot use a Drupal 6 database instance as part of a Drupal 7 instance.  You must set up a clean Drupal 7 instance, and then migrate the content from a Drupal 6 instance into it, using the standard procedures for upgrading from Drupal 6 to Drupal 7.

To do this, you use something known as "table prefix".  When you install Drupal (both 6 and 7) on the database setup page you get during installation, you can expand a tab to get to Advanced options.  This gives you access to some extra options, including "table prefix". 

The "table prefix" allow for multiple instances sharing the database.  For instance, if your existing Drupal 6 site is set up without a table prefix, you can use the table prefix d7_ to set up a Drupal 7 configuration in the same database that will not interfere with your Drupal 6 configuration.