创建 C# 或 JDBC 客户端到 Babelfish 的连接
在下面,您可以找到一些使用 C# 和 JDBC 类连接到 Babelfish for Aurora PostgreSQL 的示例。
例 :使用 C# 代码连接到数据库集群
string dataSource = 'babelfishServer_11_24'; //Create connection connectionString = @"Data Source=" + dataSource +";Initial Catalog=
your-DB-name
" +";User ID=user-id
;Password=password
"; SqlConnection cnn = new SqlConnection(connectionString); cnn.Open();
例 :使用通用 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
"; // Load the SQL Server JDBC driver and establish the connection. System.out.print("Connecting Babelfish Server ... "); Connection cnn = DriverManager.getConnection(connectionUrl);
例 :使用特定于 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
"); Connection con = ds.getConnection();