先贴段jsp代码试试

类别:Java 点击:0 评论:0 推荐:

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
     String strName = "";
     String strSex = "" ;
     try
     {
      Class.forName("com.mysql.jdbc.Driver").newInstance();    
      String url = "jdbc:mysql://localhost:3306/samp_db" ;
      String strUser = "root" ;
      String strPasswd = "123" ;
      Connection conn = DriverManager.getConnection(url,strUser,strPasswd) ;
      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE) ;
      String strSql = "select * from student" ;
      ResultSet rs = stmt.executeQuery(strSql) ;
      while(rs.next())
      {
        strName = rs.getString("name") ;
        strSex  = rs.getString("sex") ;      
        out.print(strName) ;
        out.println(strSex) ;
       }           
       stmt.close() ;
       conn.close() ;
   }
   catch(Exception e)
    {
        e.printStackTrace() ;
    }    
%>
</body>
</html>

 

本文地址:http://com.8s8s.com/it/it14183.htm