1.xp只能安装个人版,标准版和企业版不能安装。 安装混合登陆模式,用户名sa,密码sa
2.如果以前安装过后来删除了,再安装会出现问题,因为注册表(regedit)中的内容没有删除,应该先删除文件夹,以及注册表中以下内容:
HKEY_CURRENT_USER\Software\Microsoft\MicrosoftSQL Server
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MicrosoftSQL Server
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer
重启之后再安装
3.企业管理器要在服务管理器运行之后才行。
4.安装SP3,sp3.exe只是解压,解压后点击setup才是真正的安装,之后重启
5.安装JDBC
在企业管理器中新建一个数据库DBtest,
使用以下代码测试:
package test; import java.*; import java.sql.Driver; 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 = "DBtest"; private final String userName = "sa"; private final String password = "sa"; // Informs the driver to use server a side-cursor, // which permits more than one active statement // on a connection. private final String selectMethod = "cursor"; // Constructor public Connect() { } private String getConnectionUrl() { return url + serverName + ":" + portNumber + ";databaseName=" + databaseName + ";selectMethod=" + selectMethod + ";"; } private java.sql.Connection getConnection() { try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con = java.sql.DriverManager.getConnection(getConnectionUrl(), userName, password); if (con != null) System.out.println("Connection Successful!"); } catch (Exception e) { e.printStackTrace(); System.out.println("Error Trace in getConnection() : " + e.getMessage()); } return con; } /* * Display the driver properties, database details */ public void displayDbProperties() { java.sql.DatabaseMetaData dm = null; java.sql.ResultSet rs = null; try { con = this.getConnection(); if (con != null) { dm = con.getMetaData(); System.out.println("Driver Information"); System.out.println("\tDriver Name: " + dm.getDriverName()); System.out .println("\tDriver Version: " + dm.getDriverVersion()); System.out.println("\nDatabase Information "); System.out.println("\tDatabase Name: " + dm.getDatabaseProductName()); System.out.println("\tDatabase Version: " + dm.getDatabaseProductVersion()); System.out.println("Avalilable Catalogs "); rs = dm.getCatalogs(); while (rs.next()) { System.out.println("\tcatalog: " + rs.getString(1)); } rs.close(); rs = null; closeConnection(); } else System.out.println("Error: No active Connection"); } catch (Exception e) { e.printStackTrace(); } dm = null; } private void closeConnection() { try { if (con != null) con.close(); con = null; } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws Exception { Connect myDbTest = new Connect(); myDbTest.displayDbProperties(); } }
之后,
包资源管理器-->包名右键"构建路径"-->配置构建路径-->java构建路径-->库-->添加外部JAR
jdbc文件夹中的lib目录下的三个jar文件(msbase.jar、mssqlserver.jar、msutil.jar)选择进去就可以了.
运行java代码,可以看到:
Connection Successful!
Driver Information
Driver Name: SQLServer
Driver Version: 2.2.0040
Database Information
Database Name: Microsoft SQL Server
Database Version: Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
Avalilable Catalogs
catalog: db_JXC
catalog: DBtest
catalog: master
catalog: msdb
catalog: Northwind
catalog: pubs
catalog: tempdb