class="copyCode code-tool" data-toggle="tooltip" data-placement="top" data-clipboard-text=" quot;-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ing dbuser="root"; //数据库账户 String dbpwd="root"; //数据库密码 try { Class.forName("com.mysql.jdbc.Driver"); //加载驱动 JspStudy } catch (ClassNotFoundException e) { e.printStackTrace(); } //取得数据库连接conn Connection conn=DriverManager.getConnection(url, dbuser, dbpwd);; PreparedStatement ps=null; ResultSet rs=null; //声明数据库字段 String id=""; String title=""; String img=""; try { String sql="select * from res"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()) { id=rs.getString(1); title=rs.getString(2); img=rs.getString(3); out.println("ID:"+id+"
"); out.println(title+"
"); out.println("
"+"
"); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if(rs!=null) rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if(ps!=null) ps.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } %>