JSON_EXTRACT in Mysql by JAVA does not work

Asked

Viewed 51 times

0

Hello guys I have a field in mysql called itemvenda of type JSON with the following data:


{"secao": {"codigo": "114", "descricao": "FRUTAS 1"}, "gondola": "1", "cestaBasica": false, "departamento": {"codigo": "018.001", "descricao": "FRUTAS"}, "vendaSemEstoque": true, "unidadesComerciais": [{"precos": [{"pComissao": 0.0, "precoVenda": 4.58, "margemIdeal": 45.0, "tabelaPreco": {"codigo": 1, "descricao": "TABELA A VISTA"}, "usuarioEdicao": {"nome": "MARINEZ", "codigo": 4}, "comissaoPrincipal": false, "descontoBloqueado": true, "pCustoOperacional": 14.25, "pDescontoPermitido": 0.0, "precoVendaAnterior": 3.98}], "excluido": false, "pesoBruto": 0.0, "cobraFrete": false, "pesoLiquido": 0.0, "codigosBarras": [{"codigoBarras": "121", "codigoBalanca": false, "codigoBarrasPrincipal": false}, {"codigoBarras": "221725855120", "codigoBalanca": false, "codigoBarrasPrincipal": true}], "fatorConversao": {"fator": 1.0, "unidadeMedida": {"codigo": "PC", "descricao": "PACOTE"}}, "pCustoOperacional": 0.0}], "fornecedorEspecifico": {"codigo": null, "nomeRazao": "FRUTAS 1"}}

Then I do an SQL to filter the Units of Measure of this JSON as follows:


select JSON_EXTRACT(ite.itemvenda, "$.unidadesComerciais[*].fatorConversao.unidadeMedida.codigo") 'unidadeMedidaJSON' from item ite

When run by direct Workbench it works, but when run by java class returns null to me, someone has already had this problem?

1 answer

0

Staff is the following before not using JSON and had a function that picked up the String before running and did a toLowerCase() and as the json is casesentive was bugging my sqls, even so thank you very much.

  • Personal how do I mark as solved?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.