Skip to content

unknown pStmtId error when close one preparedstatement that statement is same with another in one connection #1236

@PanternBao

Description

@PanternBao
  • dble version:
    2.19.03.0 or earlier
  • preconditions :
    no
  • configs:

schema.xml

<dble:schema xmlns:dble="http://dble.cloud/">
    <schema name="schema1" dataNode="dn1">
    </schema>

    <dataNode name="dn1" dataHost="localhost1" database="db1"/>
    <dataNode name="dn2" dataHost="localhost1" database="db2"/>
    <dataNode name="dn3" dataHost="localhost2" database="db1"/>
    <dataNode name="dn4" dataHost="localhost2" database="db2"/>

    <dataHost name="localhost1" maxCon="1000" minCon="1" balance="0" switchType="1" slaveThreshold="100">
        <heartbeat>show slave status</heartbeat>
        <!-- can have multi write hosts -->
        <writeHost host="hostM1" url="localhost:3306" user="root"
                   password="123456"/>
    </dataHost>

    <dataHost name="localhost2" maxCon="1000" minCon="1" balance="0" switchType="1" slaveThreshold="100">
        <heartbeat>show slave status</heartbeat>
        <writeHost host="hostS1" url="localhost:3307" user="root"
                   password="123456"/>
    </dataHost>
</dble:schema>

server.xml

    <user name="root">
        <property name="password">123456</property>
        <property name="schemas">schema1</property>
    </user>

  • steps:
    step1. execute the following code
public static void main(String[] args) {
        Connection con = getConnection();
        PreparedStatement statement1 = null;
        PreparedStatement statement2 = null;
        ResultSet rs = null;
        try{

            statement1 = con.prepareStatement("select concat(?,?) as result");
            statement1.setString(1,"hello");
            statement1.setString(2,"stmt");
            rs = statement1.executeQuery();
            while (rs.next()) {
                String result = rs.getString("result");
                System.out.println("result:  " + result);
            }

            statement2 = con.prepareStatement("select concat(?,?) as result");
            statement2.setString(1,"hello");
            statement2.setString(2,"stmt1");
            statement1.close();

            rs = statement2.executeQuery();
            while (rs.next()) {
                String result = rs.getString("result");
                System.out.println("result:  " + result);
            }
        } catch(Exception e){
            e.printStackTrace();
        } finally {
        }
    }

    public static Connection getConnection(){
        Connection connection = null;
        final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        final String DB_URL = "jdbc:mysql://localhost:8066/schema1?useServerPrepStmts=true";
        final String USER = "root";
        final String PASS = "123456";
        try {
            Class.forName(JDBC_DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            connection = DriverManager.getConnection(DB_URL, USER, PASS);
        }catch(Exception e){
            e.printStackTrace();
        }
        return connection ;
    }

  • expect result:
    1.
result:  hellostmt
result:  hellostmt1
  • real result:
    1. Unknown pStmtId when executing.
  • supplements:
    1.

Metadata

Metadata

Assignees

Labels

protocolresolveproblem has been fixed by developer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions