jquery - Mysql ORDER BY length(col), col 不工作

标签 jquery html mysql jsp

     Mysql employee table 

Mysql database table

注意:这里的emp_id是varchar

  String query="select * from employee ORDER BY length(emp_id),emp_id";

  if i run only the above query it works fine......
  Query ouput :

enter image description here

当我运行下面的 jsp 代码时,这个查询不起作用

<html><head>
        <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <link href="jquery.dataTables.css" rel="stylesheet" type="text/css"/>
    <script src="jquery.dataTables.js"></script>
</head>
<body>
    <div class="container">
        <table id="example" class="display" width="100%" border="1">
            <thead><tr>
                                        <th>EMPLOYEE_ ID</th>
                    <th>NAME</th>
                                        <th>DEPARTMENT</th>
                                        <th>DESIGNATION</th>              
               </tr></thead>            
<tbody>
        <%    
          try
             { 
              String query="select * from employee ORDER BY length(emp_id),emp_id";
              Class.forName("com.mysql.jdbc.Driver");
              Connection con = (Connection)   DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
              Statement stmt=con.createStatement();
              ResultSet rs=stmt.executeQuery(query);
              while(rs.next())
                              {                                   
                               %>
                               <tr> 
                                   <td><%=rs.getString(1)%></td>
                                   <td><%=rs.getString(2)%></td>
                                   <td><%=rs.getString(3)%></td>
                                   <td><%=rs.getString(4)%></td>
                               </tr>
                               <% } %>
    </tbody></table>
                            <%
                              rs.close(); stmt.close();con.close();
             }
              catch(Exception e)
                               {  e.printStackTrace(); }
                            %>          
            </div>
<script>
     $(document).ready( function () {
 var table = $('#example').DataTable();
     } );
    </script></body></html>

jsp 的输出:

enter image description here 注意:在我的表中 emp_id 是 varchar................................................ ..................................................... ..................................... 请帮助我....

最佳答案

可能是您的 jquery 采用了默认的排序样式...

关于jquery - Mysql ORDER BY length(col), col 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23968224/

相关文章:

php - 用php显示每个数据中的子数据

html - 在不改变背景图像比例的情况下设置 SVG 的动画高度

html - 重新定位 Font Awesome 图标

javascript - 谷歌地图无法正确加载

php - Android中通过php上传照片到Ubuntu服务器

jquery - 使用 CodeMirror 进行拖放功能

javascript - 检查加载时选定的下拉菜单?

javascript - 如何根据 DropDownList 选择验证 TextBox - JavaScript

javascript - 某些属性在 IE 中不起作用

mysql - 如何使用 WHERE id IN(1,2,3,4) 获得均匀分布