Myeclipse 与sqlserver连接出错

douchog_13k 2008-10-07 10:04:49
我的是xp系统,我们在学j2ee要用到Myeclipse连接数据库sqlserver2000可是出现
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] Error establishing socket
的错误,sp3补丁已经装上,telnet 127.0.0.1 1433时连接出错。
哪位高人能帮一下忙啊。可加我QQ:365832692
...全文
172 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihan6415151528 2008-10-13
  • 打赏
  • 举报
回复
sp4 补丁
East271536394 2008-10-10
  • 打赏
  • 举报
回复
打一个SP4的补丁
用下面的代码就OK
package com.shop.db;


import java.sql.*;
import java.io.*;

/**************************************************
* author:East(张栋芳)
* date:2008-6-13
* note:打开数据库的连接,和关闭连接
**************************************************/

public final class DataBaseOperator {

public DataBaseOperator() {
}

/***
*连接数据库用户指定driver,url,user,pwd
*/
public static Connection createConnection(String driver,String url,String user,String pwd){
Connection con = null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,user,pwd);
}catch(ClassNotFoundException ce){
ce.printStackTrace();
}catch(SQLException se){
se.printStackTrace();
}
return con;
}
/***
*连接数据库用户用默认的SQL server 2000的纯驱动
*/
public static Connection createConnection(){
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=pubs";
String user = "sa";
String pwd = "";
return createConnection(driver,url,user,pwd);
}
/***
*创建一个连接通过配制文件
*/
public static Connection createConnection(String fileName){
String driver="";
String url="";
String user="";
String pwd="";
BufferedReader in = null;

try{
in = new BufferedReader(new FileReader(fileName));
driver = in.readLine();
url = in.readLine();
user = in.readLine();
pwd = in.readLine();
in.close();
}catch(IOException ioe){
ioe.printStackTrace();

}
return createConnection(driver,url,user,pwd);
}
/***
*创建一个连接桥驱动
*/
public static Connection createConnection(String driver,String url){
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:myodbc";
String user = "sa";
String pwd = "";
return createConnection(driver,url,user,pwd);
}
/***
*关闭连接。con,pstmt,rs;
*/
public static void closeAll(Connection con,PreparedStatement pstmt,ResultSet rs){
try{
if(rs != null)rs.close();
if(pstmt != null) pstmt.close();
if(con != null) con.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
rs = null;
pstmt = null;
con = null;

}
}

/***
*关闭连接。con,pstmt;
*/
public static void closeAll(Connection con,PreparedStatement pstmt){
try{
if(pstmt != null) pstmt.close();
if(con != null) con.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
pstmt = null;
con = null;
}
}
/***
*关闭连接。con
*/
public static void closeAll(Connection con){
try{
if(con != null) con.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
con = null;
}
}
/**
*关闭一个连接con,stmt,rs
*/
public static void closeAll(Connection con,Statement stmt,ResultSet rs){
try{
if(con != null) con.close();
if(stmt != null) stmt.close();
if(rs != null) rs.close();
}catch(SQLException se){
se.printStackTrace();
}
}
/**
*关闭一个连接con,stmt
*/
public static void closeAll(Connection con,Statement stmt){
try{
if(con != null) con.close();
if(stmt != null) stmt.close();
}catch(SQLException se){
se.printStackTrace();
}
}

}
dujun3245350 2008-10-09
  • 打赏
  • 举报
回复
接分
java__king 2008-10-09
  • 打赏
  • 举报
回复
sp3不够啊,要用SP4的
Rainyword 2008-10-08
  • 打赏
  • 举报
回复
数据库JDBC驱动有没装?
sebatinsky11111 2008-10-08
  • 打赏
  • 举报
回复
呵呵,首先:下个补丁,sp4的,装上,问题解决,
或者是可以在myeclipse中测试你的数据库是否可以连上,用myeclipse中的数据库连接,自己测试一下,
或者按照七楼的说得,看看一些端口设置,或者是其他的什么问题。解决,我的没有问题,没有升级,也没有测试,直接连接,还有就是设置断点,看看你的语法上有问题没?
月夜雪 2008-10-08
  • 打赏
  • 举报
回复
可能是端口号问题。你按照一下步骤来,试下

1. 打开企业管理器,依次在控制台根目录 ->Microsoft SQL Servers->SQL Server 组,列出一部分数据库服务器。

2. 右击我们要连接的数据库服务器,选择属性,在常规选项卡点击网络配置弹出新窗口。

3. 在启用的协议区域我们选择 TCP/IP ,点击属性按钮,弹出新窗口。在这个窗口有网络协议默认值设置,我在这里看到我的默认端口是:“ 4067” (就开这里是不是1433了)。因面在使用 1433 连接数据库时出错。
kuria001 2008-10-08
  • 打赏
  • 举报
回复
是会出错,下个SP4就好了,我也碰到过,当时查了好久。。。
deeplyloving 2008-10-08
  • 打赏
  • 举报
回复
lz多给我一点分``现在拿分好辛苦
deeplyloving 2008-10-08
  • 打赏
  • 举报
回复
去下个sqlserver补丁包就可以了
http://download.microsoft.com/download/d/d/e/dde427eb-0296-4eac-a47c-d11a66b03816/chs_sql2kasp3.exe
dyh1981 2008-10-08
  • 打赏
  • 举报
回复
你是不是起了防火墙呀!关了应该没事了!我也碰过你提到的原因!
yami251139 2008-10-07
  • 打赏
  • 举报
回复
http://www.java2000.net/p394
这个。。。说的非常之详细。。。
landyshouguo 2008-10-07
  • 打赏
  • 举报
回复
关注!!!!!!!!
xuhaiyang 2008-10-07
  • 打赏
  • 举报
回复
升到sp4就好了

58,453

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧