193kuanglv
发贴: 6
积分: 0
|
于 2006-04-06 08:54
快一个星期了 我真的搞不通啊!!! 就是连不上SQL SERVER
import java.util.*; import java.sql.*;
public class TestDB { public static void main(String[] args) { try { runTest(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex.getNextException(); } } } public static void runTest() throws SQLException { Connection con = TestDB.getConnection(); try { Statement state = con.createStatement();
state.execute("CREATE TABLE Greetings (Message CHAR(20))"); state.execute("INSERT INTO Greetings VALUES ('hello world!')");
ResultSet result = state.executeQuery("SELECT * FROM Greetings"); result.next(); System.out.print(result.getString(1)); //state.execute("DROP TABLE Greetings"); } finally { con.close(); } } public static Connection getConnection() throws SQLException { String drivers = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; System.setProperty("jdbc.drivers", drivers); String url = "jdbc:microsoft:sqlserver://192.168.0.3:1433;databasename=COREJAVA"; String username = "sa"; String password = "awdz123";
return DriverManager.getConnection(url,username,password); } } 使用系统版本: windows 2003 server enterprise edition 使用编译工具: JBuilder 2006 使用数据库版本 SQL Server 2000 连接时出现的异常: 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:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at testdb.TestDB.getConnection(TestDB.java:49) at testdb.TestDB.runTest(TestDB.java:23) at testdb.TestDB.main(TestDB.java:11) 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) 环境变量已设置,也将3个.jar文件拷到目标文件夹了,SQL Server 使用Ado.net 连接时没有问题。 一开始以为各软件有问题,全部重新安装(包括系统),搞了一个礼拜,快崩溃了!!! 求你们了,一定得帮个忙, 因为这个问题每天吃不好,睡不着, 请帮我一下,一定,请帮我!!! QQ357037014
|