If the substance being measured is liquid water, then 12 grams of water will occupy 12 ml because the density of liquid water is 1 g/ml. If a substance other than liquid water is being measured, the density of that substance is needed to calculate how many grams of it would occupy 12 ml.
The mass of a substance that will fit into 12 ml depends on the particular substance. For example, 12 ml of feathers would have less mass than 12 ml of steel ball bearings, and 12 ml of helium gas would have even less mass than the feathers. This is why the density of the substance is needed to calculate how many grams of that specific substance would occupy 12 ml.