java preparedStatement占位符问题
占位符,只是用来替代值,不能用来替代表名
ps = conn.prepareStatement("select * from "+ tableName);
//prep.setString(1, tableName);//运行报错
ResultSet result = ps.executeQuery();
实际上也可以理解:
就比如这句:
select * from t_user where name=?;
执行ps.setString(1,"张三");后变成:
select * from t_user where name='张三';
用在表名上会变成:
select * from 'xxx';//多了单引号