Topic: :-O求助 JSP中通过JDBC连接SQL SERVER 的问题

  Print this page

1.:-O求助 JSP中通过JDBC连接SQL SERVER 的问题 Copy to clipboard
Posted by: longchuan
Posted on: 2006-07-29 14:47

各位大侠,是不是在连接SQL Server 2000时,如果没有安装SQL Server 的SP4补丁包,Tomcat就打不开1433端口啊.如果要安装,又该如何安装呢.还有就是SQL Server 2000的JDBC驱动要放在哪个包下面.是Webapp/root/web-inf 下 ,还是common下的lib目录下.请各位看下我写的这些东西有什么问题没有:谢谢各位啦.
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=newdate";
String username="sa";
String password="";
Connection con = DriverManager.getConnection(url,username,password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from book");

新手,很急啊.

2.Re::-O求助 JSP中通过JDBC连接SQL SERVRE 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-07-29 19:43

怎么没有人回呢,一下午了啊,问题太菜吗.

3.Re::-O求助 JSP中通过JDBC连接SQL SERVRE 的问题 [Re: longchuan] Copy to clipboard
Posted by: chengbd
Posted on: 2006-07-30 01:19

如果要安装,又该如何安装呢?
google一下,去MS的站点下载安装。

应该放在Webapp/yourwebapp/web-inf/lib下

4.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: why
Posted on: 2006-07-30 22:38

>如果没有安装SQL Server 的SP4补丁包,Tomcat就打不开1433端口啊
二者無關

>请各位看下我写的这些东西有什么问题没有
有錯誤請貼出來
不要讓人花太多時間看

5.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: sothis
Posted on: 2006-07-31 10:18

>是不是在连接SQL Server 2000时,如果没有安装SQL Server 的SP4补丁包,To>mcat就打不开1433端口啊.
是的

>如果要安装,又该如何安装呢.
从微软sql server产品区下载Sp4,(运行)展开到一个临时目录,运行目录中的升级程序进行升级。

6.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: sothis] Copy to clipboard
Posted by: why
Posted on: 2006-07-31 11:19

sothis wrote:
>是不是在连接SQL Server 2000时,如果没有安装SQL Server 的SP4补丁包,Tomcat就打不开1433端口啊.
是的

I think SP3a would suffice.
(revised: from SP3 to SP3a)

7.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: yjpwy
Posted on: 2006-07-31 17:10

没有关系```
必须得安装sp4还有驱动
````

把错误的贴子贴出来``大家看看```

8.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-01 14:29

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
  org.apache.jsp._0603_jsp._jspService(_0603_jsp.java:104)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
  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.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:512)
  java.sql.DriverManager.getConnection(DriverManager.java:171)
  org.apache.jsp._0603_jsp._jspService(_0603_jsp.java:64)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
  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)

先谢谢各位了,现在把错误贴在上面,烦劳各位再给看一下,再次感谢大家.

9.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: FireFox666
Posted on: 2006-08-04 22:10

SQL SERVER 2000的驱动是一定要装的 , 默认安装就OK了。 你安装好了在看看在把错误的帖子拿出来大家看看 好吗? 我也刚学JAVA 呵呵 一起学习下了。

10.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-05 18:21

谢谢大家先,更要谢谢Why.以后一定注意.

11.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: why
Posted on: 2006-08-05 18:59

Search for Error establishing socket on http://www.cjsdn.net/post/search

e.g. from http://www.cjsdn.net/post/view?bid=10&id=167516
2. Install M$ SQL Server SP3a, not SP3.
(I have no experience with M$ SQL Server 2000 SP4)

3. Error establishing socket & issues with Windows XP SP2
Here're the official responses from M$ :
http://support.microsoft.com/kb/313178
How to configure Windows XP Service Pack 2 (SP2) for use with SQL Server
http://support.microsoft.com/kb/841249
How to enable SQL Server connectivity on Windows XP Service Pack 2
http://support.microsoft.com/kb/841251
How to manually enable TCP/IP on Windows XP Service Pack 2 for SQL Server 2000
http://support.microsoft.com/kb/841252

12.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-06 22:08

又要麻烦大家了
我把SQL Server重装了一下.JDBC的驱动放在这里:
D:\Tomcat 5.0\webapps\ROOT\WEB-INF\lib下.安装SP3a时出错.所以又装了SP4.但还是出错.错误如下:
exception

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
  com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

(我在装SQ3a时为什么装了不了呢.提示没有安装Analysis Services 2000,请问这个和SQL Server 2000是什么关系.还有一个叫desk什么的也是这样一个类似的组件吧.哪位能给我解答一下吗.我在这里搜过,但没有找到.所以又要麻烦大家,可能又要麻烦Why兄了.鉴于大家对我的帮助,我一定会力所能及的帮助别人的.

13.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-06 22:10

补充一下,我的数据库没有设密码

14.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: why
Posted on: 2006-08-07 10:21

longchuan wrote:
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
......
我在这里搜过,但没有找到.

0. you should set a password
1. you should set the authentication mode of your SQL Server to Mixed mode.
http://www.cjsdn.net/post/view?bid=10&id=144328 的標題就是"未与信任 SQL Server 连接相关联"Dead


SQL Server 2000 Analysis Services is the next generation of the OLAP Services component in SQL Server 7.0.
http://www.microsoft.com/sql/solutions/bi/bianalysis.mspx

15.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-07 12:42

Disapproved我就知道还要麻烦你老兄.唉!再这样下去,我都不敢发贴了.老麻烦别人,心里过意不去啊.又是我疏忽了,我去看了.真是要谢谢你.无以言表啊.Disapproved.

16.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-07 13:23

Big SmileBig Smile谢谢谢谢,问题解决了.这点问题麻烦你们好几天了啊.

17.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: wt_adam
Posted on: 2006-08-07 15:20

为什么这么多人都用Microsoft的驱动呢,不过Microsoft的驱动我也试过,也可以,不过我正常都用jtds.jar
这个文件一定要放在java_home\jre\lib\ext,也不知道什么原因,理论上放在WEB-INF/lib/下就可以了,classpath下都可以,给你一个代码,在你的机器上测试一下

import java.sql.*;

public class Dbtest {

Connection con;
Statement sta;
ResultSet rs;

String driver;
String url;
String user;
String pwd;

public Dbtest() {
driver = "net.sourceforge.jtds.jdbc.Driver";
url = "jdbc:jtds:sqlserver://127.0.0.1:1433/Northwind";
user = "sa";
pwd = "你的密码";
init();
}

public void init() {
try {
Class.forName(driver);
System.out.println("driver is ok");
con = DriverManager.getConnection(url, user, pwd);
System.out.println("conection is ok");
sta = con.createStatement();
rs = sta.executeQuery("select * from Categories");
while (rs.next())
System.out.println(rs.getString("CategoryName"));
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args [])
{
new Dbtest();
}
}

18.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-08 13:51

什么也不是,但不是不断恶意发贴,测试一下.

19.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: longchuan
Posted on: 2006-08-09 12:12

我在另外的机器上重试一下.再不行我就不用这个帐号了.

20.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: Novo
Posted on: 2006-08-09 20:51

终于可以发贴了,来了好几次了.

21.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: 潇潇
Posted on: 2006-08-10 14:43

最好不要sa不带密码的用户,自己新创建一个用户来得更简单呀.

22.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: 潇潇
Posted on: 2006-08-10 14:45

===>SQL Server 2000的JDBC驱动要放在哪个包下面.是Webapp/root/web-inf 下 ,还是common下的lib目录

应该放在common下的lib目录下.

23.Re::-O求助 JSP中通过JDBC连接SQL SERVER 的问题 [Re: longchuan] Copy to clipboard
Posted by: Novo
Posted on: 2006-08-10 22:57

刚用不久,所以没有用密码.还在学习中.


   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