【发布时间】:2014-07-21 00:25:50
【问题描述】:
Mysql employee 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 :
当我运行下面的 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 的输出:
注意:在我的表中 emp_id 是 varchar................................................. ..................................................... …………………………………………………………………………………………………………………………………… 请帮帮我....
【问题讨论】:
-
您认为您在 JSP 代码或 SQL 查询中有错误吗?
-
mysql查询或我的jsp页面没有错误......
-
emp_id 为什么你有 varchar?
-
因为我的 emp_id 列也包含字母数字值
-
你的 Datatable() 的一些默认选项是否可以改变你的出现顺序?