主题:用jsp连sql2000出现错误,帮帮我~~~~~~~~``
各位大侠,近日在winXP系统下安装了sqlserver2000数据库,并安装了Microsoft SQL Server 2000 Driver for JDBC,且将其下的三个jar包都拷入了tomcat/common/lib/目录下,对classpath也进行了配置,jsp代码如下
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
<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="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select job_id,job_desc from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) { %>
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
<% } %>
<% out.print("数据库操作成功,恭喜你"); %>
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
运行后显示
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:520)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:615)
org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:487)
org.apache.jasper.xmlparser.XercesEncodingDetector.load(XercesEncodingDetector.java:1000)
org.apache.jasper.xmlparser.XercesEncodingDetector.skipString(XercesEncodingDetector.java:951)
org.apache.jasper.xmlparser.XercesEncodingDetector.scanXMLDecl(XercesEncodingDetector.java:1209)
org.apache.jasper.xmlparser.XercesEncodingDetector.getEncoding(XercesEncodingDetector.java:108)
org.apache.jasper.xmlparser.XercesEncodingDetector.getEncodingMethod(XercesEncodingDetector.java:121)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:57)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:313)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:170)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
是怎么回事?
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %>
<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="admin";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select job_id,job_desc from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) { %>
您的第一个字段内容为:<%=rs.getString(1)%><br>
您的第二个字段内容为:<%=rs.getString(2)%><br>
<% } %>
<% out.print("数据库操作成功,恭喜你"); %>
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
运行后显示
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:520)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:615)
org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:487)
org.apache.jasper.xmlparser.XercesEncodingDetector.load(XercesEncodingDetector.java:1000)
org.apache.jasper.xmlparser.XercesEncodingDetector.skipString(XercesEncodingDetector.java:951)
org.apache.jasper.xmlparser.XercesEncodingDetector.scanXMLDecl(XercesEncodingDetector.java:1209)
org.apache.jasper.xmlparser.XercesEncodingDetector.getEncoding(XercesEncodingDetector.java:108)
org.apache.jasper.xmlparser.XercesEncodingDetector.getEncodingMethod(XercesEncodingDetector.java:121)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:57)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:313)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:170)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
是怎么回事?