apache / shardingsphere-example

Sharding-Sphere examples
Apache License 2.0
974 stars 731 forks source link

【4.0.0-RC2】HintManager.setDatabaseShardingValue() 使用PreparedStatement 不生效, Statement则生效 #195

Closed ctjy closed 4 years ago

ctjy commented 4 years ago

Question

For English only, other languages will not accept.

Before asking a question, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it. ---------------------------PreparedStatement ------------------------------ private static void processWithHintValue(final DataSource dataSource) throws SQLException {

    String sql = "SELECT * from t_order ";
    try (HintManager hintManager = HintManager.getInstance();
         Connection connection = dataSource.getConnection();
         PreparedStatement statement = connection.prepareStatement(sql)) {
        setHintValue(hintManager);
        statement.execute();
        //statement.execute("SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id");
       // statement.execute("select * from t_order_item");
       // statement.execute("INSERT INTO t_order (user_id, address_id, status) VALUES (1, 1, 'init')");
    }
}

[INFO ] 2019-11-15 17:08:56,599 --main-- [ShardingSphere-SQL] Actual SQL: ds_0 ::: SELECT from t_order
[INFO ] 2019-11-15 17:08:56,599 --main-- [ShardingSphere-SQL] Actual SQL: ds_1 ::: SELECT
from t_order

--------------------------statement----------------------------------------- private static void processWithHintValue(final DataSource dataSource) throws SQLException {

    String sql = "SELECT * from t_order ";
    try (HintManager hintManager = HintManager.getInstance();
         Connection connection = dataSource.getConnection();

// PreparedStatement statement = connection.prepareStatement(sql)) { // setHintValue(hintManager); // statement.execute(); Statement statement = connection.createStatement()) { setHintValue(hintManager); statement.execute(sql); //statement.execute("SELECT i. FROM t_order o, t_order_item i WHERE o.order_id = i.order_id"); // statement.execute("select from t_order_item"); // statement.execute("INSERT INTO t_order (user_id, address_id, status) VALUES (1, 1, 'init')"); } }

[INFO ] 2019-11-15 17:11:04,793 --main-- [ShardingSphere-SQL] Actual SQL: ds_0 ::: SELECT * from t_order

terrymanu commented 4 years ago

For english only