eshop在两个地方用到了首先,你检查你的数据源
其次,你检查你的sql语句,并输出,直接到数据库中执行看是否报错
再次,检查你的SQL Server服务是否启动,端口是否正确如果以上三步检查后,应该不会有错

解决方案 »

  1.   

    好象都对的啊!
    <%@ page contentType="text/html;charset=gb2312" %>
    <%@ include file="common.jsp" %>
    <%@ page import="java.util.*,java.sql.*" %>
    <%@ page language="java"%>
    <html>
     <head><title>TitleBookDescription</title></head>
     <%@ include file="banner.jsp" %>
     <br>
     <% 
      String bookId=request.getParameter("bookId");
      if(bookId==null)bookId="1";
     try
     {
    String url= "jdbc:odbc:eshop";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn= DriverManager.getConnection(url);
    java.sql.Statement stmt;
    stmt= conn.createStatement();


    String queryMessage = "select * from books ";
    queryMessage += "where "+"("+"id="+bookId+")";


    out.println(queryMessage);
    ResultSet rs= stmt.executeQuery(queryMessage);
      %>
       <p>书名:<%= rs.getString("id")%></p>
       <p>作者:<em><%= rs.getString("name") %></em>&nbsp;&nbsp;
       <br>
       <p>价格(元):<%= rs.getFloat("price") %></p>
       <p>销售数量:<%= rs.getInt("saleAmount") %></p>
       <p>评论:<%= rs.getString("description") %></p>
       <%  rs.close();
    stmt.close();
    conn.close();
    }catch(Exception e){
    out.println(e.getMessage());
    }
        %>
       <p><strong><a href="<%= request.getContextPath()%>/catalog.jsp?Add=<%= bookId%>">
       加入购物车
       </a>&nbsp;&nbsp;&nbsp;
       <a href="<%= request.getContextPath()%>/catalog.jsp">继续购物</a></p>
       </strong>
       </body>
    </html>
    输出结果:BOOKSTORE 
    --------------------------------------------------------------------------------select * from books where (id=3) [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 'books' 无效。 
    加入购物车     继续购物