<table border= "2 ">
<%
while(rs.next()){
out.print( " <tr> ");
for(int i=1;i <count;i++)
out.println( " <td> "+rs.getString(i).substring(0,10)+ " </td> ");
out.print( " </tr> ");
}
%>
</table>
為什麼運行時說第六行有錯誤,把.substring(0,10)去掉就可以?
------解决方案--------------------
for(int i=1;i <count;i++)
{
String str = rs.getString(i);
out.println( " <td> "+(str==null||str.length <10)?str:str.substring(0,10)+ " </td> ");
}
------解决方案--------------------
判断是否为空或长度是否大于10
str = rs.getString(i);
str=str!=null?str: " ";
if(str.length() <10)
out.println( " <td> "+str+ " </td> ");
else
out.println( " <td> "+str.substring(0,10)+ " </td> ");