新闻类别读取出错,请各位兄弟帮看看错在哪儿,急!
下面就是我要用到的读取新闻类别类的一个方法:
/***************************************************************************
* 函数名:ReadClass
* 作 用:读取所有类别 参 数:无
* 返回值:字符串
**************************************************************************/
public String ReadClass() {
try {
Connection Conn = DBConn.getConnection();
Statement stmt = Conn.createStatement(1004, 1007);
Statement stmt1 = Conn.createStatement(1004, 1007);
String sql = "select * from BigClass order by BigClassID ";
ResultSet rs = stmt.executeQuery(sql);
StringBuffer sb = new StringBuffer();
sb
.append( " <br> <br> <table width=\ "90%\ " border=\ "1\ " align=\ "center\ " cellpadding=\ "2\ " cellspacing=\ "0\ "> \r\n ");
sb
.append( " <tr> <td height=\ "27\ " colspan=\ "3\ " background=\ "images/bg.gif\ "> ");
sb
.append( " <div align=\ "center\ " class=\ "title\ "> <strong> 新闻类别管理 </strong> </div> </td> ");
sb.append( " </tr> \r\n ");
sb.append( " <tr> \r\n ");
sb
.append( " <td height=\ "25\ " colspan=\ "4\ "> <strong> <a href=\ "Admin_Class.jsp?Action=AddBigClass\ "> ");
sb
.append( " <font color=\ "#ff6600\ "> [增加大类] </font> </a> </strong> </td> \r\n ");
sb.append( " </tr> \r\n ");
sb.append( " <tr> \r\n ");
sb
.append( " <td height=\ "25\ "> <div align=\ "center\ " class=\ "chinese\ "> <b> 类别名称 </b> </div> </td> \r\n ");
sb
.append( " <td> <div align=\ "center\ " class=\ "chinese\ "> <b> 添加时间 </b> </div> </td> \r\n ");
sb
.append( " <td> <div align=\ "center\ " class=\ "chinese\ "> <b> 操作 </b> </div> </td> \r\n ");
sb.append( " </tr> \r\n ");
// 如果表中没有任何记录,刚给出提示信息
if (!rs.next()) {
sb
.append( " <tr height=\ "25\ " bgcolor=\ "#d6dff7\ " class=\ "info1\ "> <td colspan=\ "3\ "> \r\n ");
sb
.append( " <div align=\ "center\ "> <b> 暂时没有任何大类! </b> </div> </td> </tr> \r\n ");
} else {
while (!rs.isAfterLast()) {
int BigClassID = rs.getInt( "BigClassID ");
String BigClassName = rs.getString( "BigClassName ");
String BigClassInfo = rs.getString( "BigClassInfo ");
int[] iBNum = ReadClassNews(BigClassID, true, false);
sb.append( " <tr class=\ "chinese\ "> \r\n ");
sb.append( " <td width=\ "40%\ " height= '22 ' title=\ " ");
sb.append(BigClassInfo);
sb
.append( "\ "> <div align=\ "left\ "> <img src= 'images/+.gif '> <b> ");
sb.append(BigClassName + " </b> [ " + BigClassID + "] ");
sb.append( " [ " + iBNum[0] + "/ " + iBNum[1]
+ "] </div> </td> \r\n ");
sb.append( " <td width=\ "30%\ "> <div align=\ "center\ "> ");
sb.append(rs.getString( "AddTime "));
sb.append( " </div> </td> \r\n ");
sb
.append( " <td width=\ "30%\ " class=\ "chinese\ "> <div align=\ "right\ "> [ <a href=\ "Admin_Class.jsp?Action=AddSClass&BigClassID= ");
sb.append(BigClassID);
sb
.append( "\ "> 增加子类 </a> ][ <a href=\ "Admin_Class.jsp?Action=EditBigClass&BigClassID= ");
sb.append(BigClassID);
sb
.append( "\ "> 修改 </a> ][ <a href=\ "Admin_Class.jsp?Action=DelBig&BigClassID= ");
sb.append(BigClassID);
sb.append( "\ "> 删除 </a> ] </div> </td> \r\n ");
sb.append( " </tr> \r\n ");
String sql1 = "select * from SmallClass where BigClassID= "
+ BigClassID;
ResultSet rs1 = stmt1.executeQuery(sql1);
while (rs1.next()) {
int SClassID = rs1.getInt( "SmallClassID ");
int[] iSNum = ReadClassNews(SClassID, false, false);
sb.append( " <tr bgcolor=\ "#d6dff7\ "> \r\n ");
sb
.append( " <td class=\ "chinese\ " height=\ "20\ " Title=\ " "
+ rs1.getString( "SmallClassInfo ")
+ "\ "> <div align=\ "left\ " class=\ "chines\ "> ");
sb.append( " <img src= 'images/-.gif '> ");
sb.append(rs1.getString( "SmallClassName ") + " [ "
+ SClassID + "] [ " + iSNum[0]
+ "] </div> </td> \r\n ");
sb
.append( " <td class=\ "chinese\ "> <div align=\ "center\ " class=\ "chines\ "> ");
sb.append(rs1.getString( "AddTime ") + " </div> </td> \r\n ");
sb
.append( " <td> <div align=\ "right\ " class=\ "chinese\ "> [ <a href=\ "Admin_Class.jsp?Action=EditSClass&SClassID= ");
sb.append(SClassID);
sb
.append( "\ "> 修改 </a> ] [ <a href=\ "Admin_Class.jsp?Action=DelSmall&SClassID= ");
sb.append(SClassID);
sb.append( "\ "> 删除 </a> ] </div> </td> \r\n ");
sb.append( " </tr> \r\n ");
}
rs.next();
}
}
sb.append( " </table> ");
sb.append( " <br> <br> ");
rs.close();
stmt.close();
Conn.close();
return sb.toString();
} catch (Exception e) {
// e.printStackTrace();
System.out.print(e.getMessage());
return "No ";
}
}
数据库中有数据。我还想问一下,怎么样处理Jsp和MySql中出现的乱码问题,最好能给我提供一些代码,谢谢各位兄弟了。
[解决办法]
晕 看的好累啊 你连错误都没有给出来,谁知道你的程序错在那里
你是想考考大家的水平还是考眼力里.就你这样,一年后也不会有人给你答案!!!
数据库编码的问题,首先你要确定mysql使用的什么编码,然后程序处理一下和mysql编码一样就可以解决编码问题.
[解决办法]
我看你应该是个新手吧
看你的代码写得不怎么样,去看看mvc的规范吧!
[解决办法]
Jsp和MySql中出现的乱码问题 这样的文章很多的,你找下就好了,我没用mysql
[解决办法]
改数据库的编码格式改到是中文为止,哈哈