用mysql编译:Java Web开发实战经典(基础篇)课后题答案 060501_〖第05章:JSP基础语法〗_第01题

以下为调试通过代码,需要更详细的可以私信我
要修改的地方:
1、
改为
 
  
 
2、数据库的连接:
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
	public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:MLDN" ;
	public static final String DBUSER = "scott" ;
	public static final String DBPASSWORD = "tiger" ;
改为:
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver"; 
	public static final String DBURL = "jdbc:mysql://localhost:3306/mldn"; 
	public static final String DBUSER = "用户名"; 
	public static final String DBPASSWORD = "t密码"; 
 
  
<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
代码如下:
emp_list_false.jsp 
  
<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


  
    My JSP 'emp_list_true.jsp' starting page
  
  
  
  
  <%! 
  public static final String URL = "emp_list_false.jsp"; 
   %>
  <%! 
	public static final String DBDRIVER = "org.gjt.mm.mysql.Driver"; 
	public static final String DBURL = "jdbc:mysql://localhost:3306/mldn"; 
	public static final String DBUSER = "root"; 
	public static final String DBPASSWORD = "toor"; 
%>
<%
	Connection conn = null ;
	PreparedStatement pstmt = null ;
	ResultSet rs = null ;
%>
<%
    int currentPage = 1;
    int lineSize = 5;
    int allRecorders = 0;
    int pageSize = 1;
    int lsData[]={1,3,5,7,9,10,15,20,25,30,35,100};
 %>
 <%
   try{
   currentPage = Integer.parseInt(request.getParameter("cp"));
  }catch(Exception e){}
  try{
  lineSize = Integer.parseInt(request.getParameter("ls"));
  }catch(Exception e){}
  %>
<%
   Class.forName(DBDRIVER);
   conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
   String sql = "SELECT COUNT(empno) FROM emp ";
   pstmt = conn.prepareStatement(sql);
   rs = pstmt.executeQuery();
   if(rs.next()){
     allRecorders = rs.getInt(1);
   }
%>

雇员列表

<% pageSize = (allRecorders +lineSize -1)/lineSize ; %> <% sql = "SELECT empno,ename,job,hiredate,sal,comm FROM emp ORDER BY empno"; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); %>
> > > 跳转到页 每页显示
<% for(int x=0;x<(currentPage-1)*lineSize;x++){ rs.next(); } for(int x=0;x <% } } %>
编号 姓名 职位 雇佣日期 工资 奖金
<%=empno%> <%=ename%> <%=job%> <%=hiredate%> <%=sal%> <%=comm%>
<% conn.close(); %>


















你可能感兴趣的:(Java)