donkeylord 发表于 2017-11-22 21:33:56

有关jsp连数据库

jar包已装入,连接正常。但显示如下错误
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'wel.jsp' starting page</title>
   
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">   
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

</head>

<body>
    SUccess<%=request.getParameter("user") %><br>
    <a href="login.jsp">返回重新登陆</a>
    <h1>用户信息列表</h1>
    <%
               //定义四个分页会用到的变量
         int pageSize=3;
         int pageNow=0;
         int pageCount=3;
         int rowCount=3;
         String driverClass = "com.mysql.jdbc.Driver";
         Class.forName(driverClass).newInstance();
             Connection ct=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","");
                //?autoReconnect=true&useUnicode=true&characterEncoding=gbk&mysqlEncoding=utf8
       

             Statement sm=ct.createStatement();
             ResultSet rs=sm.executeQuery("select * from student1");
             
             if(rs.next()){
                   rowCount=rs.getInt(1);
                   
             
             }
             if(rowCount%pageSize==0){
                    pageCount=rowCount/pageSize;
                    }else{pageCount = rowCount/pageSize+1;
                    }
             //查询需要显示的记录
             rs=sm.executeQuery("select top"+pageSize
             +" * from student1 where userid not in (select top "
             +pageSize*(pageNow-1)+" userid from student1)");
   %>
   <table border="1">
   <tr><td>用户id</td><td>用户名字</td><td>密码</td></tr>
   </table>
   <%
       while(rs.next()){
      %>
       <tr><td><%=rs.getInt(1) %></td><td><%=rs.getInt(2) %></td>
       <td><%=rs.getInt(3) %></td></tr>
       <%
       }
      %>
      </table>
      
   
   
      %>
   
   
   
   </table>
</body>
</html>

我不知道。_ 发表于 2017-12-8 14:19:45

{:10_279:}

Byboy 发表于 2017-12-19 15:03:12

you have an error in your sql syntax; 说的很明白了呀 sql语句有错误
页: [1]
查看完整版本: 有关jsp连数据库