标题:我的SQL数据库为什么连接不上呢?
只看楼主
lxm520910
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2007-10-3
 问题点数:0 回复次数:0 
我的SQL数据库为什么连接不上呢?
我写了个java程序,连接 SQL Server数据库。可老是有异常,我又看不懂,哪位大虾能给点意见啊!小弟谢谢了!!

import java.sql.*;


public class JDBCExample{
    public static void main(String args[]){
        try{            
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=master","sa","");
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select * from student");
            while(rs.next()){
                System.out.print("学号: " + rs.getInt(1));
                System.out.print("\t姓名: " + rs.getString(2));
                System.out.print("\t性别: " + rs.getInt(3));   
                System.out.println("\t年龄: " + rs.getString(4));
            }
            rs.close();
            stmt.close();
            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}


下面的是异常信息:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at test.JDBCExample.main(JDBCExample.java:9)
搜索更多相关主题的帖子: SQL 数据库 java public jdbc 
2008-06-05 19:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-217838-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087051 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved