Topic: 请求高手解决一个JDBC连接的问题。

  Print this page

1.请求高手解决一个JDBC连接的问题。 Copy to clipboard
Posted by: jin3shan
Posted on: 2006-05-19 14:27

错误信息如下:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /testMssql.jsp:25

22: %>
23: <%
24:
25: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
26: Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev","","");
27: Statement stmt=con.createStatement();
28: ResultSet rst=stmt.executeQuery("select * from book;");

Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: com/microsoft/jdbc/base/BaseDriver
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:99)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
  java.lang.ClassLoader.defineClass1(Native Method)
  java.lang.ClassLoader.defineClass(ClassLoader.java:620)
  java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
  java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
  java.net.URLClassLoader.access$100(URLClassLoader.java:56)
  java.net.URLClassLoader$1.run(URLClassLoader.java:195)
  java.security.AccessController.doPrivileged(Native Method)
  java.net.URLClassLoader.findClass(URLClassLoader.java:188)
  java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  java.lang.ClassLoader.loadClass(ClassLoader.java:299)
  java.lang.ClassLoader.loadClass(ClassLoader.java:251)
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1339)
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
  org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:127)
  org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
  java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
  java.lang.Class.forName0(Native Method)
  java.lang.Class.forName(Class.java:164)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:70)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.
请问一下是哪个地方的错误,是JDBC配置错误,还是代码错误。

2.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: why
Posted on: 2006-05-20 11:07

> java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
Please put the M$ jarMoon in the appropiate location:
<Tomcat>/common/lib (%CATALINA_HOME%\common\lib)
or
<Webapp>/lib

3.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: jin3shan
Posted on: 2006-05-20 12:47

谢谢你的回答!但是,我装好了jar,并设置了CLASSPATH,还是会出现同样的错误.请问是为什么呢.我的JDK版本为jdk-1_5_0_06-windows-i586-p.exe;tomcat版本为apache-tomcat-5.5.17.exe 数据库Mssql server2000我的设置如下:
JAVA_HOME: D:\jdk1.5
CATALINA_HOME: D:\Tomcat 5.5
CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\msbase.jar;%CATALINA_HOME%\common\lib\mssqlserver.jar;%CATALINA_HOME%\common\lib\msutil.jar
Path: %JAVA_HOME%\D:\jdk1.5\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
程序代码如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<html>
<body>
以下是从Ms sql server数据库读取的数据:<hr>
<table border=1>
<tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<%

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver:127.0.0.1:1433;DatabaseName=jspdev","sa","");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from book;");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+trans(rst.getString("bookId"))+"</td>");
out.println("<td>"+trans(rst.getString("bookName"))+"</td>");
out.println("<td>"+trans(rst.getString("publisher"))+"</td>");
out.println("<td>"+rst.getFloat("price")+"</td>");
out.println("</tr>");
}
//关闭连接、释放资源
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>

请再帮我看看.

4.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: jin3shan
Posted on: 2006-05-20 13:15

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /testMssql.jsp:26

23: <%
24:
25: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
26: Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev","sa","sa");
27: Statement stmt=con.createStatement();
28: ResultSet rst=stmt.executeQuery("select * from book;");
29: while(rst.next())

Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:99)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
  com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
  com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
  com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
  com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
  com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
  com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
  java.sql.DriverManager.getConnection(DriverManager.java:525)
  java.sql.DriverManager.getConnection(DriverManager.java:171)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:71)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
这又是什么错误.

5.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: why
Posted on: 2006-05-21 22:03

jin3shan wrote:
我装好了jar,并设置了CLASSPATH,还是会出现同样的错误.请问是为什么呢.我的JDK版本为jdk-1_5_0_06-windows-i586-p.exe;tomcat版本为apache-tomcat-5.5.17.exe 数据库Mssql server2000我的设置如下:
JAVA_HOME: D:\jdk1.5
CATALINA_HOME: D:\Tomcat 5.5
CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;...

1. Tomcat may not use the CLASSPATH -- I am not sure about this.
2. I won't use folder names with spaces for my Java projects.
3. %JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar are not really necessary

> 还是会出现同样的错误
Did you restart Tomcat?
Is it really the same error?? In the next post, you wrote:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket


> Error establishing socket
Please do a seach on this board first.
There are many many many topics about this, including the topmost one.

Please let us know whether you could solve the problem and how.

6.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: jin3shan
Posted on: 2006-05-22 08:44

是不是还需要配置web-inf/xml.

7.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: jin3shan
Posted on: 2006-05-22 09:32

没设置web-in/xml.错误信息又成了这样.
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: Exception in JSP: /testMssql.jsp:26

23: <%
24:
25: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
26: Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver:127.0.0.1:1433;DatabaseName=jspdev","sa","sa");
27: Statement stmt=con.createStatement();
28: ResultSet rst=stmt.executeQuery("select * from book;");
29: while(rst.next())

Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:99)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
  com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
  com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
  java.sql.DriverManager.getConnection(DriverManager.java:525)
  java.sql.DriverManager.getConnection(DriverManager.java:171)
  org.apache.jsp.testMssql_jsp._jspService(testMssql_jsp.java:71)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
请问下是怎么回事呢?又该怎么解决呢.

8.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: why
Posted on: 2006-05-22 12:41

jin3shan wrote:
是不是还需要配置web-inf/xml.

In your case, I don't think so.

> 没设置web-in/xml.错误信息又成了这样.
What are you talking about?Question

> Error establishing socket
READ the topmost topic on this board, i.e.
[database] JDBC with M$ SQL Server (including Error establishing socket)

9.Re:请求高手解决一个JDBC连接的问题。 [Re: jin3shan] Copy to clipboard
Posted by: CRYSPARK
Posted on: 2006-06-22 11:55

这个问题吗

mssql的驱动一共有3个你都放进去了吗?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923