编程语言

img hairi

先贴段jsp代码试试

发表于2004/10/27 11:14:00  781人阅读

<%@ 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>

 

阅读全文
0 0

相关文章推荐

img
取 消
img