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

run sql "select * from pp"....exception is "java.sql.SQLSyntaxErrorException: Table 'test.pp' doesn't exist" #3035

Closed
beijing-penguin opened this issue Sep 13, 2019 · 2 comments

Comments

@beijing-penguin
Copy link
Contributor

beijing-penguin commented Sep 13, 2019

1、my databases have two simple table: pp_0 and pp_1.
2、i use the project newest version code is incubator-shardingsphere's dev or 4.0.0-RC2
3、shardingjdbc config is:

		// 配置真实数据源
	    Map<String, DataSource> dataSourceMap = new HashMap<>();
	    // 配置第一个数据源
	    DruidDataSource dataSource1 = new DruidDataSource();
	    dataSource1.setUrl("jdbc:mysql://localhost:3306/test?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT");
	    dataSource1.setUsername("root");
	    dataSource1.setPassword("123456");
	    dataSourceMap.put("ds0", dataSource1);
	    
	    TableRuleConfiguration testTableRuleConfig = new TableRuleConfiguration("pp");
	    testTableRuleConfig.setTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("id", "pp_${id % 2}"));
	    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
	    shardingRuleConfig.getTableRuleConfigs().add(testTableRuleConfig);
	    // 获取数据源对象
	    DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, new Properties());
try {
		    DbHelper db = new DbHelper(dataSource);
		    List<Map<String,Object>> list = db.selectList("select * from pp");
		    System.out.println(JSON.toJSONString(list));
	    }catch (Exception e) {
	    	e.printStackTrace();
		}
	    ConnectionManager.closeConnectionAll();

4、

java.sql.SQLSyntaxErrorException: Table 'test.pp' doesn't exist
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227)
	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.getQueryResult(PreparedStatementExecutor.java:116)
	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.access$2(PreparedStatementExecutor.java:114)
	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor$2.executeSQL(PreparedStatementExecutor.java:108)
	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor$2.executeSQL(PreparedStatementExecutor.java:1)
	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute0(SQLExecuteCallback.java:68)
	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback.execute(SQLExecuteCallback.java:57)
	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.syncGroupExecute(ShardingExecuteEngine.java:125)
	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.parallelExecute(ShardingExecuteEngine.java:102)
	at org.apache.shardingsphere.core.execute.ShardingExecuteEngine.groupExecute(ShardingExecuteEngine.java:83)
	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:73)
	at org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:56)
	at org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor.executeCallback(AbstractStatementExecutor.java:133)
	at org.apache.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.executeQuery(PreparedStatementExecutor.java:111)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.executeQuery(ShardingPreparedStatement.java:116)
	at org.dc.jdbc.core.utils.JDBCUtils.setParamsReturnRS(JDBCUtils.java:55)
	at org.dc.jdbc.core.DbHelper.selectList(DbHelper.java:88)
	at org.dc.jdbc.core.DbHelper.selectList(DbHelper.java:98)
	at com.dc.shardingtest.App.main(App.java:44)

5、I hope that the result is “pp_0” and "pp_1" all data

@KomachiSion
Copy link
Member

KomachiSion commented Sep 16, 2019

@beijing-penguin , Please add actualNodes to testTableRuleConfig like

TableRuleConfiguration testTableRuleConfig = new TableRuleConfiguration("pp", "ds0.pp_${0..1}");

@beijing-penguin
Copy link
Contributor Author

yes,Problem solved,ths....

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

No branches or pull requests

3 participants