JDBC连接SQL Server 2005的方法
一、下载安装
1、SQL Server 2005 Express Edition
下载 SQL Server 2005 Express Edition(下载页面):
http://msdn.microsoft.com/vstudio/express/sql/download/
安装完数据库后设置ICP/IP协议启动(这一步不能少,默认是TCP/IP不启用的),具体如下:
(1)打开SQL Server Configuration Manager
(2)转到SQL Server 2005 Network Configuration(SQL Server 2005网络配置)
再转到 Protocols for SQLEXPRESS(SQL的协议)
(3)将TCP/IP设置为Enabled(启用)
(4)双击TCP/IP项,转到IP Addresses(IP地址)页
(5)IP All中设置TCP Port为1433
(6)重新启动服务(方法如下):
第一步:转到SQL Server 2005 Network Configuration(SQL Server 2005网络配置)
第二步:打开左侧的 SQL Server 2005服务 选项,右侧便出来很多SQL相关服务
第三步:选中 SQL Server (SQL) 项,右键重新启动即可
2、SQL Server2005数据库JSP JDBC驱动
下载地址:
http://download.microsoft.com/download/1/c/a/1cae7cc0-c010-4e0c-b1b8-7915360ee0b9/sqljdbc_1.0.809.102_chs.exe
安装或者解压,取得sqljdbc.jar文件,该文件即为JDBC驱动。将sqljdbc.jar放到classpath。(web application中放在WEB-INF/lib下)
二、连接数据库SQL Server2005的Java代码
import java.sql.*;
public class ConnectSQL2005 {
public static void main(String[] args)throws Exception{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=tempdb";//数据库名需要自定义
String user="sa"; //用户需要自定义
String password="1814"; //密码需要自定义
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from Student";//SQL查询语句需要自定义
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
相关文档:
1.创建数据库
--exec xp_cmdshell 'mkdir d:\project'--调用DOS命令创建文件夹,使用此句需要启动SQL的外围工具
if exists(select * from sysdatabases where name='数据库名')
drop database 数据库名
set nocount on ......
转自:http://hi.baidu.com/arslong/blog/item/b23307e76252342cb8382001.html
Item01
连接字符串中常用的声明有:
服务器声明:Data Source
、Server
和Addr
等。
数据库声明:Initial Catalog
和DataBase
等。
集成Windows
账号的安全性声明:Integrated
Security
和Trusted_Connection
等。
使用数据库 ......
use AdventureWorks
GO
SELECT c.LastName from Person.Contact c;
SELECT * from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID; n
SELECT ProductID,Name,ProductNumber,ReorderPoint
from Production.Product
where ProductID in( select ProductID fro ......
--SQL高级程序设计:子查询
use AdventureWorks
GO
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL;
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
ON e.ContactID = c.ContactID
WHERE e.EmployeeID IN ......
问题
如何让T-SQL测试套件把测试用例结果直接写入文本文件
设计
使用ActiveX技术实例化一个FileSystemObject对象,然后通过OpenTextFile()和WriteLine()方法直接把测试结果写入文件。
方案
declare @fsoHandle int,@fileID int
exec sp_OACreate 'Scr ......