我试图在下面的查询中检索总数,我该怎么做,因为我想把结果放在jTextField中,try / catch在执行的buton动作中
try {
Connection conn = new Operaciones().conectarLogin();
Statement st = conn.createStatement();
String sql = "RETURN total;"+
"CREATE OR REPLACE FUNCTION cantidad_productos()"+
"RETURNS integer AS $total$"+
"declare total integer;"+
"BEGIN SELECT count( *) into total FROM producto; END;"+
"$total$ LANGUAGE plpgsql;";
ResultSet rs = st.executeQuery(sql);
int total = rs.getInt("total");
String a = Integer.toString(total);
jTextField1.setText(a);
}catch (SQLException e) {JOptionPane.showMessageDialog(null, "Excepción de SQL: " + e);}