getConnection 方法 (java.lang.String, java.lang.String)getConnection Method (java.lang.String, java.lang.String)
01/19/2017
在此文章
嘗試與這個 SQLServerDataSource 物件所代表的資料來源建立連接,其方式是使用指定的使用者名稱和密碼。Tries to establish a connection with the data source that this SQLServerDataSource object represents by using the given user name and password.
語法Syntax
public java.sql.Connection getConnection(java.lang.String username,
java.lang.String password)
參數Parameters
usernameusername
包含使用者名稱的 字串。A String that contains the user name.
passwordpassword
包含密碼的 字串。A String that contains the password.
傳回值Return Value
例外狀況Exceptions
java.sql.SQLExceptionjava.sql.SQLException
備註Remarks
這個 getConnection 方法是由 javax.sql.DataSource 介面中的 getConnection 方法所指定。This getConnection method is specified by the getConnection method in the javax.sql.DataSource interface.
使用非 Null 使用者名稱或密碼呼叫 getConnection 方法時,將會取代初始化 SQLServerConnection 物件時,在 SQLServerDataSource 類別上所設定的使用者名稱與密碼屬性。Calling the getConnection method with a non-null user name or password will replace the user name and password properties that are set on the SQLServerDataSource class when initializing the SQLServerConnection object. 例如,如果呼叫者已經在資料來源上呼叫 setUser 和 setPassword,然後呼叫 getConnection 並提供非 Null 使用者名稱或非 Null 密碼,則 setUser 和 setPassword 所設定之使用者名稱和密碼將會由傳遞給 getConnection 的使用者名稱和密碼取代。For example, if the caller has called setUser and setPassword on the data source, and then calls getConnection and supplies a non-null user name or a non-null password, the user name and password set by setUser and setPassword will be replaced by the user name and password passed into getConnection.
注意
在此情況下,使用 setURL 方法的呼叫在 URL 內設定的使用者名稱和密碼將不會變更。The user name and password that are set inside the URL by using a call to the setURL method will not be changed in this case.
另請參閱See Also