Bom dia, então eu estou fazendo um projeto que faz uma requisição em um site e retorna o valor dos novos impostos entre outras coisas, a parte do select e enviar a requisição está tudo ok, porém a parte introduzir o valor no banco não muito, o update está desta forma:
public void alterarImposto() throws SQLException {
Retorno retorno = new Retorno();
int nacional = Integer.parseInt(retorno.getNacional());
int importado = Integer.parseInt(retorno.getImportado());
int estadual = Integer.parseInt(retorno.getEstadual());
int municipal = Integer.parseInt(retorno.getMunicipal());
int codigo = Integer.parseInt(retorno.getCodigo());
try {
ps = conexao
.prepareStatement("UPDATE TABELAIBTP "
+ "SET ALIQNAC = ?, ALIQIMP = ?, ALIQESTADUAL = ?, ALIQMUNICIPAL = ? "
+ "WHERE CODIGONCM = ?");
ps.setInt(1, nacional);
ps.setInt(2, importado);
ps.setInt(3, estadual);
ps.setInt(4, municipal);
ps.setInt(5, codigo);
ps.executeUpdate();
} catch (SQLException ex) {
throw new SQLException("Erro alterarImposto: " + ex.getMessage());
}
}
Os campos ALIQNAC, ALIQIMP, ALIQESTADUAL e ALIQMUNICIPAL são do tipo Numeric
E o metodo main está desta forma:
public static void main(String[] args) throws SQLException {
NcmDAO ncmD = new NcmDAO();
int codigo = 0;
for (ncmMOD ncm : ncmD.carregarTeste()) {
if (!"".equals(ncm.getCodigo())) {
codigo = Integer.parseInt(ncm.getCodigo());
}
if (codigo < 9999999) {
ncm.setCodigo("0" + ncm.getCodigo());
}
Client client = ClientBuilder.newClient();
Response response = client.target("https://apidoni.ibpt.org.br/api/v1/produtos?"
+ "token=" + ncm.getToken()
+ "&cnpj=" + ncm.getCnpj()
+ "&codigo=" + ncm.getCodigo()
+ "&uf=" + ncm.getUF()
+ "&ex=" + ncm.getEX()
+ "&descricao=" + ncm.getDescricao()
+ "&unidadeMedida=" + ncm.getUnidadeMedida()
+ "&valor=" + ncm.getValor()
+ ">in=" + ncm.getGtin())
.request(MediaType.APPLICATION_JSON)
.get();
String s = response.readEntity(String.class);
Gson gson = new GsonBuilder().create();
Type collectionType = new TypeToken<Retorno>() {
}.getType();
Retorno r = gson.fromJson(s, collectionType);
ncmD.alterarImposto();
System.out.println("Imposto auterado com sucesso");
System.out.println("-------------------------------------------------------------------------");
}
}
O Erro fica assim:
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.parseInt(Integer.java:615)
at dao.NcmDAO.alterarImposto(NcmDAO.java:55)
at com.softcom.produtoncm.Teste.main(Teste.java:52)