Skip to content

ShardingSphereConnection#prepareStatement(java.lang.String, java.lang.String[]) is not working #20414

@O-king

Description

@O-king

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

5.1.3-SNAPSHOT

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

return correct primary key

Actual behavior

return first db column

Reason analyze (If you can)

ShardingSphereConnection#prepareStatement(java.lang.String, java.lang.String[]) is not working

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

postgresql db:

create table if not exists t_aa (
                user_id VARCHAR(50) not null, 
                id serial primary key, 
                address_id BIGINT not null, 
                status VARCHAR(50));

Example codes for reproduce this issue (such as a github link).

    public static void test(DataSource dataSource) throws SQLException {
        final Statement statement = dataSource.getConnection().createStatement();
        statement.execute("create table if not exists t_aa (\n" +
                "                user_id VARCHAR(50) not null, \n" +
                "                id serial primary key, \n" +
                "                address_id BIGINT not null, \n" +
                "                status VARCHAR(50));");
        
        final PreparedStatement preparedStatement = dataSource.getConnection().prepareStatement("INSERT INTO t_aa (user_id, address_id, status) " +
                        "VALUES (?,?,?);"
                , new String[]{"id"});
        
        preparedStatement.setString(1, "a");
        preparedStatement.setLong(2, 2);
        preparedStatement.setString(3, "c");
        
        preparedStatement.execute();
        
        final ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
        while (generatedKeys != null && generatedKeys.next()) {
            Object userId = generatedKeys.getObject(1);
            System.out.println("resultset userId:"+userId);
        }
    }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions