import java.*;
public class Connect{
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "pubs";
private final String userName = "user";
private final String password = "password";
// Informs the driver to use server a side-cursor,
// which permits more than one active statement
// on a connection.
private final String selectMethod = "cursor";
Connection Successful!
Driver Information
Driver Name:SQLServer
Driver Version: 2.2.0022
Database Information
Database Name:Microsoft SQL Server
Database Version:Microsoft SQL Server 2000 - 8.00.384 (Intel X86)
May 23 2001 00:02:52
Copyright (c) 1988-2000 Microsoft Corporation
Desktop Engine on Windows NT 5.1 (Build 2600: )
有关排除连接故障的基本信息
下面是尝试连接到 SQL 服务器时常见的错误信息:
java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'user'.Reason:Not associated with a trusted SQL Server connection.
如果将 SQL Server 2000 的验证模式设置为“Windows 验证模式”,则会出现此错误信息。Microsoft SQL Server 2000 JDBC 驱动程序不支持使用 Windows NT 验证进行连接。您必须将 SQL Server 的验证模式设置为“混合模式”,该模式既允许 Windows 验证,也允许 SQL Server 验证。
java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for JDBC]This version of the JDBC driver only supports Microsoft SQL Server 2000. You can either upgrade to SQL Server 2000 or possibly locate another version of the driver.
当您尝试连接到 SQL Server 2000 以前的 SQL Server 版本时,则会出现此错误信息。Microsoft SQL Server 2000 JDBC 驱动程序仅支持与 SQL Server 2000 进行连接。