易截截图软件、单文件、免安装、纯绿色、仅160KB

java中如何以windows集成方式连接SQL Server

在《JDBC Driver For SQL2000/2005/2008
》一文中,邀月介绍了如何下载并使用jdbc连接SQL Server,
今天有人问起,如何以windows集成方式连接SQL Server,这个以前真没试过。
于是,打开netBeans测试了一下,代码如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testsqlconn;
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
/** *//**
*
* @author: Administrator:downmoon(3w@live.cn)
* @date:2009-9-23 18:42:32
* @Encoding:UTF-8
* @File:TestSqlbyDS/TestSqlbyDS.java
* @Package:testsqlconn
*/
public class TestSqlbyDS {
public TestSqlbyDS(){}
public void GetResutls()
{
// Declare the JDBC objects.
Connection con = null;
CallableStatement cstmt = null;
ResultSet rs = null;
try {
// Establish the connection.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setIntegratedSecurity(true);
ds.setServerName("ap4\\agronet08");//数据库实例名
ds.setPortNumber(1433);
ds.setDatabaseName("AdventureWorksLT2008");//Database Name
con = ds.getConnection();
// Execute a SQL that returns some data.
//cstmt = con.prepareCall("{call dbo.uspGetEmployeeManagers(?)}");
//cstmt.setInt(1,50);
cstmt = con.prepareCall(" select top 10 * from [SalesLT].[Product] ");//Sql
rs = cstmt.executeQuery();
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println("Product: " + rs.getString("Name") + ", " + rs.getString("ProductNumber"));
System.out.println("ListPrice: " + rs.getString("ListPrice"));
System.out.println();
}
} // Handle any errors that may have occurred.
ca


相关文档:

java备份sql server数据库 存储过程

今天给大家分享一下如何备份和回复sql server 数据,
首先确保你具有DB的最高权限
在JAVA代码中 你可以这样写public class Opp extends TestCase{
public void test1()
{
try
{
Connection con = DBUtils.getConn();
String sql="backup database tdzl to disk='d:\\tdzl.bak'";
Statement st = con.c ......

PL/SQL常用句法

1、循环插入测试数据:
SQL>
declare
maxrecords constant int:=100;
i int :=1;
Begin
for i in 1..maxrecords loop

--插入数据
Insert into TEST.EXAMPLE(name,phone,address) values('分页测试数据....','联系电话','联系地址');
end loop;
commit;
end;
此处EXAMPLE表定义为(ID number,name ......

sql输出9*9乘法口诀表

--------------方法A-----------------
程序:
declare
    i int:=1;
    v varchar2(200):=NULL;
    v1 varchar2(20):=NULL;
begin
    loop
        for k in 1..i loop
            v1:=k||' ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号