For ssh development, mysql is used for databases. ** _ When paging, you need to obtain the total data function totalCount, get totalPage, and get the code of totalCount (excluding the code such as binding parameters and checking input parameters): _ ** & quot; * ** retrieve the total number of records * protectedintgetTotalCount (Sessions, Stringsql) {construct the count query SQL & quot; SELECTCOUNT (1) FROM (& quot; + SQL + & quot ;) tmp & quot; Que paging mysqlduplicate column
For ssh development, mysql is used for databases.
When paging is performed, you need to obtain the total data function totalCount, get totalPage, and get the code of totalCount (excluding the code such as binding parameters and checking input parameters ):
/*** Get the total number of records */protected int getTotalCount (Session s, String SQL) {// Construct the count query SQL = "SELECT COUNT (1) FROM ("+ SQL +") tmp "; Query countQuery = s. createSQLQuery (SQL); // output result List countList = countQuery. list (); return (Integer) countList. get (0 );}
The above code reports "Duplicate column name 'xxxx'" in special circumstances, for example:
User table field: ** _ user_id _ **, login_name, passwd ,...
User_detail table field: user_detail_id,User_id, Address ,...
Query SQL (** _ code SQL1 _ **): select * from user u inner join user_detail ud on u. user_id = ud. user_id
The final SQL code for totalCount query (codenamed SQL2) is:
Select count (1) from (
Select * from user u inner join user_detail ud on u. user_id = ud. user_id
) Tmp
The execution reports an error because the user and user_detail tables both have the user_id field. the result of SQL1 contains the user_id field. when the tmp table is referenced in SQL2, a duplicate name error is reported.
I would like to ask the following questions:
1. if SQL 2 is executed in oracle, no error is reported. Is there a way to change the mysql settings so that no error is reported when SQL 2 is executed?
2. is there any other way to calculate totalCount?
Fresh Meat has been written by heroes.