

# C\# または JDBC クライアントから Babelfish への接続の作成
<a name="babelfish-connect-configure"></a>

以下に、C\# クラスと JDBC クラスを使用して、Babelfish for Aurora PostgreSQL に接続する例をいくつか示します。

**Example : C\# コードを使用した DB クラスターへの接続**  

```
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 クラスとインターフェースを使用した DB クラスターへの接続**  

```
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 クラスおよびインターフェイスを使用した DB クラスターへの接続**  

```
// 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();
```