The New York bank reported Thursday that it earned $5.4 billion, or $1.27 per share in the three months ending in June. That was above the $1.22 per share that analysts surveyed by FactSet had forecast. JPMorgan earned $4.8 billion, or $1.09 per share, in the same period a year ago.

Investment banking income jumped 49 percent, to $2.1 billion, as the bank collected higher fees. The bank set aside $2.6 billion for compensation to its investment bankers, down from $2.9 billion in the same period last year.

JPMorgan’s lending business faltered in the second quarter. Despite low interest rates, the bank lost $454 million in its auto and mortgage loan operations, compared with income of $364 million in the prior year.

Even in credit cards, a bright spot in recent quarters, JPMorgan’s customers weren’t spending as much, reflecting a lack of confidence in the economy. The total amount of credit card debt held by JPMorgan fell 12 percent compared with a year ago as its customers spent less. JPMorgan reduced its loan loss reserves by $1 billion as more people paid their bills on time.

JPMorgan’s stock rose 2.7 percent to $40.69 Thursday.