欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

先贴段jsp代码试试

程序员文章站 2022-06-22 13:53:33
<%@ page contenttype="text/html;charset=gb2312" %><%@ page import="java.sql.*" %>

<%@ page contenttype="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
     string strname = "";
     string strsex = "" ;
     try
     {
      class.forname("com.mysql(和php搭配之最佳组合).jdbc.driver").newinstance();    
      string url = "jdbc:mysql(和php搭配之最佳组合)://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>