

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立對 Babelfish 的 C\$1 或 JDBC 用戶端連線
<a name="babelfish-connect-configure"></a>

在下文中，您可以找到使用 C＃ 和 JDBC 類別連線至 Babelfish for Aurora PostgreSQL 的一些範例。

**Example ：使用 C\$1 程式碼來連線至資料庫叢集**  

```
string dataSource = 'babelfishServer_11_24';

//Create connection
connectionString = @"Data Source=" + dataSource
    +";Initial Catalog=your-DB-name"
    +";User ID=user-id;Password=password";
					
// [optional] To validate server certificate during TLS/SSL connection
connectionString = connectionString + ";ServerCertificate=/path/to/certificate.pem";					

SqlConnection cnn = new SqlConnection(connectionString);
cnn.Open();
```

**Example ：使用通用 JDBC API 類別和界面來連線至資料庫叢集**  

```
String dbServer = 
   "database-babelfish.cluster-123abc456def.us-east-1-rds.amazonaws.com";
String connectionUrl = "jdbc:sqlserver://" + dbServer + ":1433;" +
    "databaseName=your-DB-name;user=user-id;password=password";

// [optional] To validate server certificate during TLS/SSL connection
connectionUrl = connectionUrl + ";serverCertificate=/path/to/certificate.pem";

// Load the SQL Server JDBC driver and establish the connection.
System.out.print("Connecting Babelfish Server ... ");
Connection cnn = DriverManager.getConnection(connectionUrl);
```

**Example ：使用 SQL Server 特定 JDBC 類別和界面來連線至資料庫叢集**  

```
// Create datasource.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setUser("user-id");
ds.setPassword("password");
String babelfishServer = 
   "database-babelfish.cluster-123abc456def.us-east-1-rds.amazonaws.com";

ds.setServerName(babelfishServer);
ds.setPortNumber(1433);
ds.setDatabaseName("your-DB-name");

// [optional] To validate server certificate during TLS/SSL connection
ds.setServerCertificate("/path/to/certificate.pem"); 

Connection con = ds.getConnection();
```