Confined groundwater is an indispensable resource for the urban security of Shanghai, China, where multi-layer aquifer structures and human activities create a complex groundwater environment. An understanding of the hydrochemical characteristics and evolutionary mechanisms of groundwater is necessary for its protection and effective utilization and will be explored in this study. A total of 87 groundwater samples were collected from five confined aquifers. Hydrochemistry analysis methods such as Durov diagram, Gibbs model and Saturation index were used to determine the origin and hydrochemical evolution of the confined groundwater. The results show that the samples have two different origins, marine–continental and continental, which have different hydrochemical characteristics. Cl− content of 7.5 meq L−1 was used as a demarcation index for the two origins. The groundwater with a marine–continental-origin is dominated by ancient seawater from which Na+ and Cl− are derived, whereas Ca2+, Mg2+, and HCO3− are derived mainly from carbonate dissolution. Groundwater with a continental-origin is dominated by the effects of water–rock interaction, where major ions are derived mainly from silicate weathering and carbonate dissolution. In both types of groundwater, SO42− is mainly derived from insoluble sulfides that are present in low quantities, whereas SO42− in the few samples with high insoluble sulfide content is derived from human activities. Cation exchange is another controlling factor regarding the hydrochemical composition of groundwater, and water from the two origins have different reaction modes as follows: reverse cation exchange is dominant in marine–continental groundwater, whereas positive cation exchange is more common in continental groundwater. Over the past century, saline water has been flowing into the groundwater funnel region due to human activities, which has resulted in changes in the hydrochemical composition. The recent influx of fresh groundwater and artificial recharge has caused groundwater salinization and mineral re-dissolution.