JDBC连接自定义sqlserver数据库实例名(多个实例)
java语言中,通过jdbc访问sqlserver2005(2008) 数据库 默认 实例 可以按常用的写法来写url 连接 。代码如下: [java] view plaincopy span> font-size:12px; Connectioncn=DriverManager.getConnection( jdbc:sqlserver://localhost:1433;DatabaseName=demo
java语言中,通过jdbc访问sqlserver2005(2008)数据库默认实例可以按常用的写法来写url连接。代码如下:
[java] view plaincopy
- "font-size:12px;">Connection cn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433; DatabaseName=demo", "sa","sa");
其中localhost为sqlserver2005数据库ip,Demo为数据库名。
自命名的sqlserver数据库实例(实例名:SQL2008R2)的数据库又是如何访问?经过查资料和摸索发现url写法如下:
[java] view plaincopy
- "font-size:12px;">con = DriverManager.getConnection("jdbc:sqlserver://localhost;instanceName=SQL2008R2; DatabaseName=Demo", "sa","sa");
也可以这样写:
[java] view plaincopy
- "font-size:12px;">Connection cn = DriverManager.getConnection("jdbc:sqlserver://localhost//SQL2005; DatabaseName=Demo", "sa","sa");
注意,连接数据库自命名实例的url中没有端口号1433,这是SQLServer中的管理机制决定的。
1. 如果机器上安装的是SQLServer的默认实例(MSSQL),那么就是通过TCP 默认1433端口远程连接。如果你打开了防火墙,需要放开1433端口。
2. 如果机器上有多个数据库实例,例如 SQLServer2005, SQLServer2008, SQLServer2008R2等,而你的SQLServer2008R2安装在Named instance,例如localhost\MyInstance。这样连接默认是UDP 1434端口(可以自己指定,在第三点的第二个选项卡IP address里面IPALL里面输入SQL运行的端口),并且需要打开SQL Browser service服务。在服务 - SQL Browser service,设置为自动启动。如果你打开了防火墙,需要放开UDP
1434端口。
文章中有些内容不对,以下内容供后面的朋友参考。
微软官方说明:
http://msdn.microsoft.com/zh-cn/library/ms378428(v=sql.90).aspx
若要获得最佳连接性能,应在连接到指定实例时设置 portNumber。这将避免为了确定端口号而与服务器进行往返通讯。如果同时使用 portNumber 和 instanceName,则会优先使用 portNumber,而忽略 instanceName。
http://blog.csdn.net/jdk2006/article/details/7641399

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

The syntax differences between MySQL and SQL Server are mainly reflected in database objects, data types, SQL statements and other aspects. Database object differences include the storage engine and how filegroups are specified, and the creation of indexes and constraints. Data type differences involve differences in numeric types, character types, and date and time types. SQL statement differences are reflected in result set limitations, data insertion, update and delete operations, etc. Other differences include how identity columns, views, and stored procedures are created. Understanding these differences is important to avoid errors when using different database systems.

To delete a SQL Server database, please perform the following steps in sequence: 1. Log in to SQL Server Management Studio; 2. Expand the database node; 3. Right-click the database to be deleted; 4. Select "Delete"; 5. Confirm the deletion. Note: Deleting the database is irreversible, please make sure you have backed up important data and disconnected other objects.

SQL Server deleted data can be recovered through transaction rollback (rolling back uncommitted transactions). Database log (restore data from log). SQL Server native backup (restore database from backup). Third-party recovery tools (use advanced technology to recover data). Contact Microsoft Support (for dedicated help).

The problem that SQL Server cannot be reinstalled due to incomplete deletion can be solved by following the following steps: manually delete files and registry entries; use SQL Server installation and uninstall tools; use third-party uninstall tools; check Windows Event Viewer; restart the computer; reinstall SQL Server.

The location where the Navicat database configuration files are stored varies by operating system: Windows: The user-specific path is %APPDATA%\PremiumSoft\Navicat\macOS: The user-specific path is ~/Library/Application Support/Navicat\Linux: The user-specific path is ~/ .config/navicat\The configuration file name contains the connection type, such as navicat_mysql.ini. These configuration files store database connection information, query history, and SSH settings.
