鱼C论坛

 找回密码
 立即注册
查看: 2924|回复: 2

有关jsp连数据库

[复制链接]
发表于 2017-11-22 21:33:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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>

显示错误

显示错误
代码.jpg
数据库.jpg
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-8 14:19:45 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-19 15:03:12 | 显示全部楼层
you have an error in your sql syntax; 说的很明白了呀 sql语句有错误
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 12:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表