@@ -77,24 +77,39 @@ void test_with_clientInfo() throws SQLException {
7777 }
7878
7979 @ Test
80- void test_with_applicationName () throws SQLException {
80+ void test_with_applicationNameAndSchema () throws SQLException {
8181 DataSourceConfig ds = new DataSourceConfig ();
8282 ds .setUrl ("jdbc:postgresql://127.0.0.1:9999/app" );
83- // our application credentials (typically same as db and schema name with Postgres)
84- ds .setUsername ("app" );
85- ds .setPassword ("app_pass" );
86- // database owner credentials used to create the "app" role as needed
87- ds .setOwnerUsername ("db_owner" );
88- ds .setOwnerPassword ("test" );
83+ ds .setSchema ("fred" );
84+ ds .setUsername ("db_owner" );
85+ ds .setPassword ("test" );
8986 ds .setApplicationName ("my-application-name" );
9087
9188 DataSourcePool pool = DataSourceFactory .create ("app" , ds );
9289 try {
9390 try (Connection connection = pool .getConnection ()) {
94- try (PreparedStatement statement = connection .prepareStatement ("create table if not exists app.my_table (acol integer) ;" )) {
91+ try (PreparedStatement statement = connection .prepareStatement ("create schema if not exists fred ;" )) {
9592 statement .execute ();
9693 }
9794 connection .commit ();
95+ try (PreparedStatement statement = connection .prepareStatement ("create table if not exists fred_table (acol integer);" )) {
96+ statement .execute ();
97+ }
98+ try (PreparedStatement statement = connection .prepareStatement ("insert into fred_table (acol) values (?);" )) {
99+ statement .setInt (1 , 42 );
100+ int rows = statement .executeUpdate ();
101+ assertThat (rows ).isEqualTo (1 );
102+ }
103+ try (PreparedStatement statement = connection .prepareStatement ("select acol from fred.fred_table" )) {
104+ try (ResultSet resultSet = statement .executeQuery ()) {
105+ while (resultSet .next ()) {
106+ int res = resultSet .getInt (1 );
107+ assertThat (res ).isEqualTo (42 );
108+ }
109+ }
110+ }
111+ connection .commit ();
112+
98113 try (PreparedStatement statement = connection .prepareStatement ("select application_name from pg_stat_activity where usename = ?" )) {
99114 statement .setString (1 , "app" );
100115 try (ResultSet rset = statement .executeQuery ()) {
0 commit comments