<%@page contentType="text/xml;charset=UTF-8"%> <%@ page import="java.util.HashMap,java.text.ParseException,tools.*"%> <%@page import="java.sql.Connection,java.sql.DriverManager,java.sql.PreparedStatement,java.sql.ResultSet,java.sql.SQLException"%> <% //request.setCharacterEncoding("gb2312"); String pagenum=request.getParameter("page"); String limit=request.getParameter("limit"); String sidx =request.getParameter("sidx"); //String sord =request.getParameter("sord"); String _search=request.getParameter("_search"); String url="select id,channel_id,channel_name,channel_addr from game.T_GAME_WAP_CHANNEL_ADDR order by id"; if(_search==null||"false".equals(_search)){ url= "select id,channel_id,channel_name,channel_addr from game.T_GAME_WAP_CHANNEL_ADDR order by id"; }else{ String searchField=request.getParameter("searchField"); String searchString=request.getParameter("searchString"); if(searchString==null||"".equals(searchString)){ url= "select id,channel_id,channel_name,channel_addr from game.T_GAME_TYPE order by id"; }else{ if("channel_id".equals(searchField)){ url="select id,channel_id,channel_name,channel_addr from game.T_GAME_WAP_CHANNEL_ADDR where channel_id like '%"+searchString+"%' order by id"; }else if("channel_name".equals(searchField)){ url="select id,channel_id,channel_name,channel_addr from game.T_GAME_WAP_CHANNEL_ADDR where channel_name like '%"+searchString+"%' order by id"; } } } if(sidx==null) sidx="1"; if(pagenum==null) pagenum="1"; if(limit==null) limit="25"; int total_result_count = 0; int total_page_count = 0; int per_page = Integer.parseInt(limit); int cur_page_num = Integer.parseInt(pagenum); java.util.LinkedList<HashMap> result = new java.util.LinkedList<HashMap>(); Connection conn = null; PreparedStatement stmt = null; ResultSet rst = null; try { conn = getConnection("jdbc/game"); //conn = mysql(); stmt = conn.prepareStatement("select count(*) from game.T_GAME_WAP_CHANNEL_ADDR"); rst = stmt.executeQuery(); rst.next(); total_result_count = rst.getInt(1); if (total_result_count > 0) { total_page_count = (total_result_count / per_page); } if ((total_result_count % per_page) > 0) { total_page_count++; } stmt = conn.prepareStatement(url + " limit ?,?"); stmt.setInt(1, (cur_page_num-1) * per_page); stmt.setInt(2, per_page); rst = stmt.executeQuery(); while(rst.next()){ HashMap<String,String> one=new HashMap<String,String>(); int count =rst.getMetaData().getColumnCount(); for(int i=0;i<count;i++){ one.put(rst.getMetaData().getColumnName(i+1), rst.getString(i+1)==null?"":rst.getString(i+1)); } result.add(one); } //out.print("result: "+result); %> <rows> <page><%=pagenum%></page> <total><%=total_page_count%></total> <records><%=total_result_count%></records> <%for(int i=0;i<result.size();i++){ HashMap map=result.get(i); %> <row id='<%=map.get("id")%>'> <cell><%=map.get("id")%></cell> <cell><%=map.get("channel_id")%></cell> <cell><%=map.get("channel_name").toString().replace("\"", "").replace(":", "").replace(":", "").replace("-", "").replace("'", "").replace("&", "").replace("<", "").replace(">", "")%></cell> <cell><%=map.get("channel_addr")%></cell> </row> <%}%> </rows> <% } catch (Exception e) { e.printStackTrace(); } finally { if (rst != null) { try { rst.close(); rst = null; } catch (SQLException ex) { rst = null; } } if (stmt != null) { try { stmt.close(); stmt = null; } catch (SQLException ex) { stmt = null; } } if (conn != null) { try { conn.close(); conn = null; } catch (SQLException ex) { conn = null; } } } %>