[转]jdbc连接sql server 2005

本文介绍如何使用SQL Server 2005 Express Edition与JDBC驱动进行配置,包括设置混合模式安全性、启用SQL浏览器服务及TCP/IP协议等步骤,并提供了一个简单的Java示例程序来验证连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sql Express is going to be a good match for the Sql Server 2005 JDBC provider, it is free, it is relatively easy to set up and deploy and it has all the power of Sql Server 2005 for low end applications.

There are a few  things to keep in mind when using Sql Express with the JDBC driver:

·         You need to enable mixed mode security when you install the server so that you can connect using user name and password.
·         Make sure that the sqlbrowser is enabled.  Sql Server configuration Manager ->SQL Server 2005 Services ->SQL Server Browser ->Start
·         The JDBC provider only works with the TCP/IP protocol which is disabled by default on Sql Express. You need to enable the TCP/IP Protocol from the SQL Server Configuration Manager that ships with SqlExpress and re-start the server. Look under SQL Server 2005 Network Configuration -> Protocols for SQLEXPRESS-> TCP/IP->Enable.

 

Once you have set up Sql Express accordingly you can connect like this:

 import java.sql.*;
 
public class test{
  
public static void main(String[] args) {
    
try{
       java.lang.Class.forName(
"com.microsoft.sqlserver.jdbc.SQLServerDriver");
       Connection c 
= java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost/SQLEXPRESS;user=myuser;password=mypass;");
       System.out.println(
"Connected!");
    }
catch(Exception ex){
       ex.printStackTrace();
    }

  }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值