Browse Source

修改获取当前查询语句的结果数目的方法

sunyj 8 years ago
parent
commit
afee61660d
1 changed files with 1 additions and 10 deletions
  1. 1 10
      src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

+ 1 - 10
src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -762,16 +762,7 @@ public class PrintServiceImpl implements PrintService {
 	 * @throws SQLException
 	 * @throws SQLException
 	 */
 	 */
 	private int getCount(Connection connection, String sql) throws SQLException {
 	private int getCount(Connection connection, String sql) throws SQLException {
-		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);
-		}
-
+		sql = "select count(1) from (" + sql + ")";
 		PreparedStatement preparedStatement = connection.prepareStatement(sql);
 		PreparedStatement preparedStatement = connection.prepareStatement(sql);
 		ResultSet resultSet = preparedStatement.executeQuery();
 		ResultSet resultSet = preparedStatement.executeQuery();
 		resultSet.next();
 		resultSet.next();