| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4991 人关注过本帖
标题:在jsp中建立留言板时出现找不到数据库
只看楼主 加入收藏
Alikce
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-6-11
结帖率:50%
收藏
 问题点数:0 回复次数:0 
在jsp中建立留言板时出现找不到数据库
<%@ page language="java" import="java.sql.*,java.util.*" pageEncoding="gbk"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    request.setCharacterEncoding("gb2312");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection(
            "jdbc:odbc:teashop", "sa", "");//数据源名
    Statement stmt = conn.createStatement(
            ResultSet.TYPE_SCROLL_INSENSITIVE,
            ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = null;//声明结果集rs
//------------------------------------------------------------
    String s_userid=(String)session.getAttribute("userid");
//------------------------------------------------------------
    int i_totalnum = 0;//结果总数
    int i_pagenum = 8;//每页书数量
    int i_totalpage = 0;//总页数
    int i_currentpage = 1;//当前页数
    String s_createid="";
    String s_subject="";
    String s_date1="";
    String s_context="";
    String s_date2="";
    String s_employeeid="";
    String s_advice="";
  //-------------------------------------------------------
    rs=stmt.executeQuery("select count(*) from notes ");
    rs.next();
    i_totalnum = rs.getInt(1);
    i_totalpage = i_totalnum / i_pagenum;
    if (i_totalnum % i_pagenum != 0) {//如果有余数,则加一页
        i_totalpage++;
    }
    String op = request.getParameter("op");

    if (op != null && op.equals("show")) {//前页为show
        String s_currentpage = request.getParameter("currentpage");
        i_currentpage = Integer.parseInt(s_currentpage);
    }
    if (op != null && op.equals("previous")) {//先前,前一页
        String s_currentpage = request.getParameter("currentpage");
        i_currentpage = Integer.parseInt(s_currentpage) - 1;
    }
    if (op != null && op.equals("next")) {//下一页
        String s_currentpage = request.getParameter("currentpage");
        i_currentpage = Integer.parseInt(s_currentpage) + 1;
    }
    if (op != null && op.equals("firstpage")) {
        i_currentpage = 1;
    }
    if (op != null && op.equals("lastpage")) {
        i_currentpage = i_totalpage;
    }

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>">
        <title>My JSP 'index.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="maincss.css">
    <script type="text/javascript">
       function checksubmit(){
         if(document.form.subject.value==""){
            alert("请您输入留言主题!");
            document.form.subject.focus();
            return false;
         }
         if(document.form.context.value==""){
            alert("请您输入留言内容!");
            document.form.context.focus();
            return false;
         }
         if(document.form.context.value.length>=100){
            alert("您收入的内容长度超过100个字!");
            document.form.context.focus();
            return false;
         }
         return true;
       }
   
    </script>
    </head>
    <body>
        <jsp:include page="top.jsp"></jsp:include>
        <form name=form action=cust/leavewords2.jsp method=post >
           <table width=750 border=0 align="center" cellspacing=0 cellpadding=0
            class=td>
              <tr><td class=diy colspan=6 align="center">用户留言</td></tr>
              <tr><td colspan=6><hr size=3 color=red /></td></tr>
              <tr>
                  <td colspan=3>
   用户留言共计<%=i_totalnum%>条,分<%=i_totalpage%>页显示,每页显示<%=i_pagenum%>条
                  </td>
                  <td colspan=3>
                     <div align="right">
                              
                                   第<%=i_currentpage%>页&nbsp;
               <!---------------------首页--------------------------->
                     <%
                       if(i_currentpage>1){
                     %>
                       <a href="cust/leavewords.jsp?op=fistpage">首页</a>
                     <%
                       }else{
                     %>
                                              首页&nbsp;
                     <%

                       }
                     %>
               <!-------------------上一页--------------------------->     
                     <%
                       if(i_currentpage>1){
                     %>
                       <a href="cust/leavewords.jsp?op=previous&currentpage=<%=i_currentpage%>">上一页</a>
                     <%
                       }else{
                     %>
                                              上一页&nbsp;
                     <%

                       }
                     %>
               <!-------------------下一页--------------------------->     
                     <%
                       if(i_currentpage!=i_totalpage){
                     %>
                       <a href="cust/leavewords.jsp?op=next&currentpage=<%=i_currentpage%>">下一页</a>
                     <%
                       }else{
                     %>
                                              下一页&nbsp;
                     <%

                       }
                     %>   
                <!-------------------末页--------------------------->     
                     <%
                       if(i_currentpage!=i_totalpage){
                     %>
                       <a href="cust/leavewords.jsp?op=lastpage">末页</a>
                     <%
                       }else{
                     %>
                                              末页&nbsp;
                     <%
                       }
                     %>                       
                   </div>
                </td>
            </tr>
            <tr>
                <td colspan=6>
                    <hr size=1 noshade="noshade" color=red />
                </td>
            </tr>
            <tr>
               <td width=10%>留言日期</td>
               <td width=10%>留言人</td>
               <td width=15%>主题</td>
               <td width=25%>内容</td>
               <td width=10%>处理日期</td>
               <td width=30%>处理意见</td>
            </tr>
            <tr>
                <td colspan=6>
                    <hr size=1 noshade="noshade" color=red />
                </td>
            </tr>
            <%
            rs=stmt.executeQuery("select * from notes order by notesid desc");
            //翻页时显示记录的逻辑-----------------------
            if(i_currentpage>i_totalpage){
               i_currentpage=i_totalpage;
            }
            int i_position=(i_currentpage-1)*i_pagenum;
            if(i_position==0){
               rs.beforeFirst();
            }else{
               rs.absolute(i_position);
            }
            //翻页时显示记录的逻辑-------------------------
            for(int i=1;i<=i_pagenum;i++){
              if(!rs.isLast()){
              rs.next();
              s_createid=(rs.getString("userid")!=null?rs.getString("userid"):"");
              s_subject=(rs.getString("subject")!=null?rs.getString("subject"):"");
              s_date1=(rs.getString("date1")!=null?rs.getString("date1").substring(0,10):"");
              s_context=(rs.getString("context")!=null?rs.getString("context"):"");
              s_employeeid=(rs.getString("employeeid")!=null?rs.getString("employeeid"):"");
              s_date2=(rs.getString("date2")!=null?rs.getString("date2").substring(0,10):"未处理");
              s_advice=(rs.getString("advice")!=null?rs.getString("advice"):"[请等待工作人员处理]");

             %>
                <tr height=30>
                   <td><%=s_date1%></td>
                   <td><%=s_createid%></td>
                   <td><%=s_subject%></td>
                   <td><%=s_context%></td>
                   <td><%=s_date2%></td>
                   <td><%=s_advice%></td>
                </tr>     
             <%
               }
            }
            %>
            <%
            
            if(s_userid!=null){
            %>
            <tr>
                <td colspan=6>
                    <hr size=1 noshade="noshade" color=red />
                </td>
            </tr>
            <tr>
               <td align="center">主题</td>
               <td colspan=5><input type=text name=subject size=25 /></td>
            </tr>
            
            <tr>
               <td align="center">留言</td>
               <td colspan=5><textarea name=context cols=70 rows=10></textarea></td>
            </tr>
            <tr><Td>&nbsp;</Td></tr>
            <tr>
               <td colspan=6 align="center">
                  <input name=submit type="submit" value=留言 onclick="return checksubmit();"/>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="reset" value=重置 />
               </td>
            </tr>
            <%
            }else{
            %>
            <tr>
                <td colspan=6>
                    <hr size=1 noshade="noshade" color=red />
                </td>
            </tr>
            <tr>
              <td colspan=6 align="center">您还没有登录,不能发表留言!请<a href="cust/index.jsp">登录</a></td>
            </tr>
            <%
            }
            %>
            
            
           </table>
        </form>
        <jsp:include page="bottom.jsp"></jsp:include>
    </body>
</html>



javax.servlet.ServletException: [Microsoft][ODBC ???????] ???????
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
    org.apache.jsp.cust.leavewords_jsp._jspService(leavewords_jsp.java:379)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause

java.sql.SQLException: [Microsoft][ODBC ???????] ???????
    sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
    sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
    sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
    sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:411)
    org.apache.jsp.cust.leavewords_jsp._jspService(leavewords_jsp.java:283)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
搜索更多相关主题的帖子: 留言板 import 数据库 数据源 java 
2016-06-14 21:16
快速回复:在jsp中建立留言板时出现找不到数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022146 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved