

# 创建 C＃ 或 JDBC 客户端到 Babelfish 的连接
<a name="babelfish-connect-configure"></a>

在下面，您可以找到一些使用 C\$1 和 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();
```