} catch (Exception e) {
}
}
if (con != null) {
try {
con.close();
} catch (Exception e) {
}
}
}
}
}
java嶄參windows鹿撹圭塀銭俊SQL Server(3)
扮寂:2011-01-19 BlogJava 剱埖
泌惚頁喘薩兆紗畜鷹議URL圭塀?夸音俶勣sqljdbc_auth.dll,酒汽謹阻?
Java
/*
* 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:TestSqlUserPwdURL/TestSqlUserPwdURL.java
* @Package:testsqlconn
*/
public class TestSqlUserPwdURL {
public TestSqlUserPwdURL(){}
public static void ShowProduct(String ip,String dbName,String user,String pwd,int port,String sql) {
try {
// ## DEFINE VARIABLES SECTION ##
// define the driver to use
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
// the database name
//String dbName = "AdventureWorksLT2008";
// define the Derby connection URL to use
String connectionURL = "jdbc:sqlserver://"+ip+":"+port+";databaseName=" + dbName;
// System.out.println(connectionURL);
Connection conn = null;
// Beginning of JDBC code sections
// ## LOAD DRIVER SECTION ##
Class.forName(driver);
System.out.println(driver + " loaded. ");
conn = DriverManager.getConnection(connectionURL, user, pwd);
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
System.out.println("ID : " + rs.getInt(1));
System.out.println("Name : " + rs.getString(2));
System.out.println("Number: " + rs.getString(3));
System.out.println("Time: " + rs.getString(4));
System.out.println();
}
rs.close();
s.close();
conn.close();
} catch (Exc
|