Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated rows is not returned #2802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

koekj
Copy link

@koekj koekj commented Feb 7, 2023

In the PreparedStatementHandler the execute function is used and afterwards the getUpdateCount is used. However in my case (Sybase) the updateCount returns zero. The two statements can be combined to 1; executeUpdate which returns the correct result.

In the PreparedStatementHandler the execute function is used and afterwards the getUpdateCount is used.
However in my case (Sybase) the updateCount returns zero. The two statements can be combined to 1; executeUpdate which returns the correct result.
@harawata
Copy link
Member

harawata commented Feb 7, 2023

Hello @koekj ,

Changing to executeUpdate has side effects and we cannot do that.

I just tested and the following test passes.
So, there may be something wrong with your code or config (if the driver really return 0, it would be a driver bug).
If you need further help, please provide information to reproduce the issue.

import static org.junit.jupiter.api.Assertions.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.jupiter.api.Test;

import net.harawata.jdbc.connection.JdbcConnection;

class SybaseTest {
  @Test
  void test() throws Exception {
    Class.forName("com.sybase.jdbc42.jdbc.SybDriver");
    String url = "jdbc:sybase:Tds:192.168.60.8:5000?serviceName=TEST";
    String username = "xxx";
    String password = "xxx";
    try (Connection con = DriverManager.getConnection(url, username, password)) {
      try (Statement st = con.createStatement()) {
        st.execute("drop TABLE  test ");
      } catch (SQLException e) {
        //
      }
      try (Statement st = con.createStatement()) {
        st.execute("CREATE TABLE test (id int, t varchar(20))");
        st.execute("insert into test (id, t) values (1, 'val')");
      }
      try (PreparedStatement stmt = con.prepareStatement("update test set t = ? where id = ?")) {
        stmt.setString(1, "val2");
        stmt.setInt(2, 1);
        assertFalse(stmt.execute());
        assertEquals(1, stmt.getUpdateCount());
      }
    }
  }
}
  • DB version : Adaptive Server Enterprise 16.0.03.02
  • Driver version : jConnect (TM) for JDBC(TM)/16.0 SP04 (Build 27487)/P/EBF29603/JDK 1.8.0/jdbc42dev/OPT/Mon Nov 9 19:10:17 PST 2020

@koekj
Copy link
Author

koekj commented Feb 10, 2023

Ok, I will check this; I'm using spring boot in combination with mybatis.
It seems that you are right; the driver I'm currently using is not given the correct answer which is
jConnect (TM) for JDBC(TM)/16.0 SP03 PL08 (Build 27463)/P/EBF29225/JDK 1.6.0/jdbcdev/OPT/Sun Jan 12 19:56:00 PST 2020
I will try the get hold on the latest jconn4 driver from sybase/sap.

@koekj
Copy link
Author

koekj commented Feb 13, 2023

Hi,
I tested it with the jconn42.jar
jConnect (TM) for JDBC(TM)/16.0 SP04 PL03 (Buil
d 27530)/P/EBF30373/JDK 1.8.0/jdbcsp04/OPT/Sun Jul 31 19:17:02 PDT 20
22
using java 17 but it doesn't seem to be working. The updateCount returns still zero, when I use the executeUpdate it returns the correct value which is 1.
assert stmt.execute() == false;
int rows = stmt.getUpdateCount();
assert rows == 1; <== returns zero
int _rows = stmt.executeUpdate();
assert _rows == 1; <== returns 1.
And the statement is very simple I'm using update x set nm=nm where relation=1 and nr=1;

@harawata
Copy link
Member

@koekj ,

Okay, then please create a small demo project like these and share it on your GitHub repo.
To investigate this issue, we need to reproduce it on our end.

@harawata
Copy link
Member

Oh, by the way, if the issue is reproducible with a plain JDBC code (i.e. without MyBatis) like the one I posted, please paste it.

@koekj
Copy link
Author

koekj commented Feb 14, 2023

I use an existing database where I'm not the "super user" so I have to see if I can setup a local database for reproduction. Did you use a docker image to get the database up and running as that would help me to speed up the reproduction.

@harawata
Copy link
Member

Last time checked, there was no official docker image, so I had to install express edition or something on my VirtualBox VM.
@SAP 👎

@koekj
Copy link
Author

koekj commented Feb 15, 2023

Ok clear. I will do the same then.

@guoweixin
Copy link

看到了,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants