Error executing Sql Server query with jtds

Asked

Viewed 50 times

1

I am like a strange situation, my code works perfectly in my environment. No tablet client does not work... The only difference is that my tablet has the developer option enabled. I created the application for version 3, the client tablet is with version 4.0.3. Follow the code that when I change error occurs: Works in both environments

 Button btnTestaConexao = (Button) layout.findViewById(R.id.btnTestarConexao);
 btnTestaConexao.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        ConsultaProduto produto = new ConsultaProduto();
        Boolean conexaoOk = produto.testaConexao(new ParametroConexao(edtBanco.getText().toString(), edtIp.getText().toString(), edtUsuario.getText().toString(), edtSenha.getText().toString(), edtInstancia.getText().toString()), (ConsultaPrecoActivity) getActivity());
        if (conexaoOk) {
            Toast.makeText(getActivity(), "Conexão estabelecida com sucesso!", Toast.LENGTH_LONG).show();

        } else {
            Toast.makeText(getActivity(), "Falha na conexão", Toast.LENGTH_LONG).show();
        }
    }
 });

When entering the code below within the if(conexãoOk) only error in the client:

 Produto _produto = produto.consultaProdutoEstoque("012162043052", getActivity());
 Toast.makeText(getActivity(), "executou consulta...", Toast.LENGTH_LONG).show();

 if (_produto != null) {
    Toast.makeText(getActivity(), "Produto: " + _produto.getDescricao(), Toast.LENGTH_LONG).show();
 }

Any suggestions?

  • What is the error? Put the error that appears in logcat.

  • Jorge, thank you for answering. In my environment not of error and in the customer the application simply aborts. I’m starting on Android, will I have some command that only works when the developer option is enabled?

  • That doesn’t seem to happen. It must be something else...

  • Pretty sure the produto must be null. Either this or another variable.

  • Check if you have the same content in the database.

  • Without having the error log becomes complicated to know what is going on...

  • Really, I agree with you, without the log becomes difficult. The data is ok, the product exists. What is strange that without the query, running only the connection test works, when I put the query nor the connection test runs. I say this because I included a Toast in the first line of the click method and it is not displaying the message.

  • So the problem has to be on those lines.

  • It seems to me that some checking is being done before executing the code itself, like a parse of the code. It is logical what I said?

  • Make an if(product!=null) and put those lines in.

  • 1

    I will make this test, return with the result. Thank you.

  • Jorge, I included all the code in the if you suggested. By clicking the button, if I can connect, the tablet displayed the message that application stopped and aborts, nor displays a Toast that included in the first line of the method. If there is an error in the connection the application correctly informs the connection failure. It must be some detail that I am not able to identify.

  • 1

    I think I’m in the way, I’ve included a Try. .catch... I’m going to do some more tests and return.

  • Good luck friend :)

  • 2

    Jorge, thank you so much for your help. The problem was in query syntax, had a column in select with IIF(PRO_VALOR> 0,PRO_VALOR,PRE_PRECO2) the prices, after replacing with 0 (zero) worked. I’m using the jtds drive to access the sql server, I know it’s not a good practice to directly access the bank. But for this application I had to use this type of connection instead of webservice. When I used Try.. catch I was able to see the messages. The IIF function only exists from the 2012 version of Sql server, the client is using the 2008 version.

  • Seixas glad you solved the problems :)

Show 11 more comments
No answers

Browser other questions tagged

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