|
|
@@ -762,8 +762,16 @@ public class PrintServiceImpl implements PrintService {
|
|
|
* @throws SQLException
|
|
|
*/
|
|
|
private int getCount(Connection connection, String sql) throws SQLException {
|
|
|
- sql = sql.toLowerCase();
|
|
|
- sql = "select count(1) " + sql.substring(sql.indexOf("from"));
|
|
|
+ Pattern pattern = Pattern.compile("^\\s*select\\s+[\\s\\S]*?\\s+from");
|
|
|
+ Matcher matcher = pattern.matcher(sql.toLowerCase());
|
|
|
+ if (matcher.find()) {
|
|
|
+ String group = matcher.group();
|
|
|
+ sql = "select count(1) from " + sql.substring(group.length());
|
|
|
+ group.length();
|
|
|
+ } else {
|
|
|
+ throw new ReportException("SQL语法错误:" + sql);
|
|
|
+ }
|
|
|
+
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
resultSet.next();
|