关于Java无法连接SQL Server 2000的问题

import java.sql.*; public class TestSQLServer { public static Connection getConnection() throws SQLException, java.lang.ClassNotFoundException{ //get connection String url="jdbc:sqlserver://localhost:1433;DatabaseName=northwind"; //loading jdbc driver for mysql System.out.println("驱动程序正在加载..."); Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); System.out.println("驱动程序加载完毕!"); String username = "sa"; String password = "sa"; //open the database connection System.out.println("opening the database connection!"); Connection con = DriverManager.getConnection(url, username, password); System.out.println(" the database connection has opened!"); return con; } public static void main(String[] args){ //String query="select * from categories"; String query1="insert categories values(10,'Hanbao','Sweet')"; String query2="insert categories values(11,'Naicha','Coffee taste')"; try{ Connection con = getConnection(); Statement stmt=con.createStatement(); stmt.executeUpdate(query1); stmt.executeUpdate(query2); stmt.close(); con.close(); System.out.println("success"); }catch(java.lang.ClassNotFoundException e){ System.out.println("ClassNotFoundException: "); System.err.println(e.getMessage()); }catch(SQLException ex){ System.out.println("SQLException: "+ex.getMessage()); } } } 编译中出现到主机TCP/IP连接失败的错误,问题原因,SQl Server2000默认没有监听1433端口检测: 用命令telnet localhost 1433提示如下:正在连接到localhost...不能打开到主机的连接, 在端口 1433: 连接失败用命令netstat -n -a,发现不能侦听1433端口解决办法:安装SP3以上版本补丁.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值