}
if (con != null) {
try {
con.close();
} catch (Exception e) {
}
}
}
}
}
java嶄參windows鹿撹圭塀銭俊SQL Server(2)
扮寂:2011-01-19 BlogJava 剱埖
潤惚戻幣?孀音欺sqljdbc_auth.dll,欺和墮議儿抹**戦心阻和?auth\x86,auth\x64\,auth\IA64和脅嗤乎猟周?岷俊鹸崙auth\x86\sqljdbc_auth.dll欺
E:\Java\jdkUpdate\jre\lib\ext\和?宸頁云字議jre揃抄。
隼朔塰佩。撹孔?
朔栖壅編阻和?窟?岷俊喘URL圭塀匆辛參糞??
旗鷹泌和?
Java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testsqlconn;
import java.sql.*;
/** *//**
*
* @author: Administrator:downmoon(3w@live.cn)
* @date:2009-9-23 18:42:32
* @Encoding:UTF-8
* @File:TestSqlByURL/TestSqlByURL.java
* @Package:testsqlconn
*/
public class TestSqlByURL {
public TestSqlByURL() {
}
public void GetResults() {
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://ap4\\agronet08:1433;databaseName=AdventureWorksLT2008;integratedSecurity=true;";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT TOP 10 * FROM [SalesLT].[Product]";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString(2) + " " + rs.getString(3));
}
} // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
}
}
if (stmt != null) {
try {
stmt.close();
|