<%@ page contentType="text/html;charset=UTF-8"%> <%@ page import="java.sql.*"%> <%!//处理字符串的方法: public String codeString(String s) { String str = s; try { byte b[] = str.getBytes("ISO-8859-1"); str = new String(b); return str; } catch (Exception e) { return str; } }%>
公告栏

<% Connection con; Statement sql; ResultSet rs; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { out.print("驱动异常"); } try { con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/db_school?useUnicode=true&characterEncoding=utf-8", "root", ""); sql = con.createStatement(); String condition = null; condition = "SELECT 公告内容,公告时间 FROM notice"; rs = sql.executeQuery(condition); while (rs.next()) //输出查询结果 { out.print("

" + rs.getString(1) + ""); out.print("" + rs.getString(2) + "
"); out.println("
"); out.println("
"); } con.close(); sql.close(); rs.close(); } catch (SQLException e1) { out.print("无法查询记录"); } %>

增加公告 修改公告 删除公告