我在用JSP连接MSSQL的时候页面出错了,代码如下:
脚本代码:
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" 
 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
   String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test1";
   String user="sa";
   String password="sa";
   Connection conn= DriverManager.getConnection(url,user,password);
  %>运行后报错代码:
     type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /conn.jsp(1,4) Invalid directive
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:517)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1444)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:154)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.JDBC装了,环境变量也加了,TOMCAT的jar文件也加了,不知道哪儿出错了,请帮忙看看,
谢谢

解决方案 »

  1.   

    是不是没有捕捉异常呢?楼主catch一下再看看结果如何 ^_^
      

  2.   

    msqlserver 服务端需要安装sp4补丁jsp连接Sql Server7.0/2000数据库  
        testsqlserver.jsp如下:  
        <%@ page contentType="text/html;charset=gb2312"%>  
        <%@ page import="java.sql.*"%>  
        <html>  
        <body>  
        <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
        String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";      //pubs为你的数据库的  
        String user="sa";  
        String password="";  
        Connection conn= DriverManager.getConnection(url,user,password);  
        Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
        String sql="select * from test";  
        ResultSet rs=stmt.executeQuery(sql);  
        while(rs.next()) {%>  
        您的第一个字段内容为:<%=rs.getString(1)%>  
        您的第二个字段内容为:<%=rs.getString(2)%>  
        <%}%>  
        <%out.print("数据库操作成功,恭喜你");%>  
        <%rs.close();  
        stmt.close();  
        conn.close();  
        %>  
        </body>  
        </html>