Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qYVUI-001uZh-3O for pgsql-general@arkaria.postgresql.org; Tue, 22 Aug 2023 17:48:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qYVUG-003Og6-3L for pgsql-general@arkaria.postgresql.org; Tue, 22 Aug 2023 17:48:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qYVUF-003Ofx-Ew for pgsql-general@lists.postgresql.org; Tue, 22 Aug 2023 17:48:15 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qYVUB-000NSa-97 for pgsql-general@lists.postgresql.org; Tue, 22 Aug 2023 17:48:13 +0000 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-76dacc4b378so119866585a.1 for ; Tue, 22 Aug 2023 10:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692726489; x=1693331289; h=in-reply-to:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=PtPK2Ir0jwmkqZg1dzWf9uf8Zk/rK3Xz1hcRWZdobg4=; b=HqD7vHwSt1JQJwr965Y4rc3SgaQMOLlkL9kwOyLbfNLtA/G/LDSZEyIj10s15tihS4 3aTbmPl1Z7fCigM7zFm1+2YC+08v1exU9wAiyUSkyGYQmstH1nFc3EIPuJ7j2YK7XGRk Fevjjrcu2J/VfM8QavSm94QyUIJNQPx+OZdqMyMYo+zeCGQyi6T6xOn/sYhU1QupRO1s UvAbunWd4+iE9lrFiarwN4W2n/INIdpyFoY+A5LILBnCowCQO6csk/mQvPxtL0Ghw+1b XX8UwXugkEb7Lf3atBsHf72IpAT4Aoq1dYCyzTFy8PJMolsQWPu5uwou0Yu/b/130jia Zu9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692726489; x=1693331289; h=in-reply-to:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PtPK2Ir0jwmkqZg1dzWf9uf8Zk/rK3Xz1hcRWZdobg4=; b=GSBQ2xLoK/EhEf9q5BE50b5AhmYYxyrrXKy4hOYFKJY+1X/otr4S9cbbrOvdYstx3h iBgkvQFcj4TxrYoLiq32b6xqav+pmF7PNK570t9pxnU4wNbSulSAjBrG3Q2jLfpBC9H3 DmCsZNwwI+WN8DMWUNXjEMMAqfpq4sNqVggXem+UhWSb3HuLIsrWXlcHsZs9EB/jLUoB ukOu8zh3T5IHbR6VNrTOrTOV+IxJilE1dy1RSLpsOMEEKT2w0EGK22RxcjIL203MUqEA 9k8WJq1GnkJz9UPv6cNFx/2fkQyJ0cAO9GBWfHgtEhIvGP+Wrlxl6ffhTLR5mC1THQG9 DFyQ== X-Gm-Message-State: AOJu0YwFai4E7hTyfWFRseuDopVORmHO243BJvAWffGHzqUXvioaN+ZE y125AqBCbyLcV3JhASKah3C21GdSDFw= X-Google-Smtp-Source: AGHT+IH0sQBLMX+k6Dl3hzrCBmk9qA/72iVK12ZdSiyo9FouDx0sN55N4tlbQfiQHZ0bJMq0uHmflQ== X-Received: by 2002:a05:620a:2224:b0:76c:ad46:2680 with SMTP id n4-20020a05620a222400b0076cad462680mr10568497qkh.44.1692726489266; Tue, 22 Aug 2023 10:48:09 -0700 (PDT) Received: from [192.168.2.170] ([67.70.150.114]) by smtp.gmail.com with ESMTPSA id w42-20020a05622a192a00b003eabcc29132sm3172776qtc.29.2023.08.22.10.48.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Aug 2023 10:48:08 -0700 (PDT) From: Amn Ojee Uw X-Google-Original-From: Amn Ojee Uw Content-Type: multipart/alternative; boundary="------------z1j704wqJn9NInie0rNI6YkP" Message-ID: Date: Tue, 22 Aug 2023 13:47:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: JDBC + PG-15 but not psql To: pgsql-general@lists.postgresql.org References: Content-Language: en-CA, es-ES In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------z1j704wqJn9NInie0rNI6YkP Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Yes your are right! I don't know why it was part of the requirement to add a JDBC line to explicitly set the behaviour of autocommint to *true*, when it was the default value. Perhaps it has to do with "just making sure it is" sort of thing. Thanks Dave, I'll let the my group know. On 8/22/23 8:31 a.m., Dave Cramer wrote: > Hi Amn, > > What I don't understand is the requirement to set autocommit to true > since this is the default ? > > Either way this is expected behaviour as psql also has autocommit true > by default. > > Thanks, > > Dave Cramer > > > > On Mon, 21 Aug 2023 at 20:57, Amn Ojee Uw wrote: > > Thanks Dave for your interest. > > In  the OP I started by explaining the difficulties when trying to > create a tabelspace using JDBC; please note that when using the > PG-15 prompt I did not have the problem. Well, it turns out that > while developing the request for help (writing the email), I > realize that my code had the following line : > *this.conn.setAutoCommit(false);*/* > */However, in my research, I had read a post mentioning that by > setting /auto commit/ to *true* the issue was solved. So, I > changed that line of code in my algorithm to : > *this.conn.setAutoCommit(true);*/* > */Which also resulted in my app working without any errors./**/ > > Please read the code-snip I submitted; there you can see that line > of code I edited; which I commented with "/*//*//*game changer!!".*/ > > Thanks again Dave, have great week. > > /* > */ > > On 8/21/23 2:51 p.m., Dave Cramer wrote: >> Hi Amn, >> >> Can you help me understand this issue better? >> >> I don't see anywhere in the code where you are attempting to >> create a tablespace ? >> >> >> Dave Cramer >> >> >> >> On Sun, 20 Aug 2023 at 11:17, Amn Ojee Uw >> wrote: >> >> Hello. >> >> I have searched the net in an attempt to find if others have >> had and resolved this challenge, but most of the sites talk >> about how, when using the psql, this error arises. In my >> case, the error arises only when access PG-15 using JDBC. >> JDBC connects to the database, but when trying to execute a >> schema, it be to create a database or to create a tabelspace >> I get this error : >> >> *StackTrace : [Ljava.lang.StackTraceElement;@7a69b07** >> **Message : ERROR: CREATE TABLESPACE cannot run inside a >> transaction block* >> >> I have used the same algorithm, but now modify to accommodate >> PG-15, when using SQLite. So the JDBC code might not be the >> problem, but the requirements needed from PG-15. >> >> Change of perspective, I resolved the concern! >> >> Here is what changed the outcome : >> --- snip --- >> >> public void connectToDatabase() throws >> ClassNotFoundException, SQLException { >>     try { >> Class.forName(this.getDatabaseClass().toString()); >>         this.conn = >> DriverManager.getConnection(this.getDatabaseUrl().toString(), >>                 this.getUserID().toString(), >> this.getUserPassword().toString()); >> >> *this.conn.setAutoCommit(true);*/*//*//*game changer!!*/ >> >>         this.pout("Connected to the PostgreSQL server, >> success!!!"); >> >>         this.stmt = this.conn.createStatement(); >>     } catch (final SQLException | ClassNotFoundException e) { >>         throw e; >>     } >> } >> >> -- >> >> All I had to do was to setAutoCommit to true, PG-15 set this >> value to false by default. >> >> >> I hope my experience can help others. >> >> --------------z1j704wqJn9NInie0rNI6YkP Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Yes your are right! I don't know why it was part of the requirement to add a JDBC line to explicitly set the behaviour of autocommint to true, when it was the default value. Perhaps it has to do with "just making sure it is" sort of thing.
Thanks Dave, I'll let the my group know.

On 8/22/23 8:31 a.m., Dave Cramer wrote:
Hi Amn,

What I don't understand is the requirement to set autocommit to true since this is the default ?

Either way this is expected behaviour as psql also has autocommit true by default.

Thanks,

Dave Cramer



On Mon, 21 Aug 2023 at 20:57, Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

Thanks Dave for your interest.

In  the OP I started by explaining the difficulties when trying to create a tabelspace using JDBC; please note that when using the PG-15 prompt I did not have the problem. Well, it turns out that while developing the request for help (writing the email), I realize that my code had the following line :
this.conn.setAutoCommit(false);
However, in my research, I had read a post mentioning that by setting auto commit to true the issue was solved. So, I changed that line of code in my algorithm to :
this.conn.setAutoCommit(true);
Which also resulted in my app working without any errors.

Please read the code-snip I submitted; there you can see that line of code I edited; which I commented with "// game changer!!".

Thanks again Dave, have great week.


On 8/21/23 2:51 p.m., Dave Cramer wrote:
Hi Amn,

Can you help me understand this issue better?

I don't see anywhere in the code where you are attempting to create a tablespace ?


Dave Cramer



On Sun, 20 Aug 2023 at 11:17, Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

Hello.

I have searched the net in an attempt to find if others have had and resolved this challenge, but most of the sites talk about how, when using the psql, this error arises. In my case, the error arises only when access PG-15 using JDBC.
JDBC connects to the database, but when trying to execute a schema, it be to create a database or to create a tabelspace I get this error :

StackTrace : [Ljava.lang.StackTraceElement;@7a69b07
Message : ERROR: CREATE TABLESPACE cannot run inside a transaction block

I have used the same algorithm, but now modify to accommodate PG-15, when using SQLite. So the JDBC code might not be the problem, but the requirements needed from PG-15.

Change of perspective, I resolved the concern!

Here is what changed the outcome :
--- snip ---

public void connectToDatabase() throws ClassNotFoundException, SQLException {
    try {
        Class.forName(this.getDatabaseClass().toString());
        this.conn = DriverManager.getConnection(this.getDatabaseUrl().toString(),
                this.getUserID().toString(),
                this.getUserPassword().toString());
        
        this.conn.setAutoCommit(true); // game changer!!
       

        this.pout("Connected to the PostgreSQL server, success!!!");

        this.stmt = this.conn.createStatement();
    } catch (final SQLException | ClassNotFoundException e) {
        throw e;
    }
}

--

All I had to do was to setAutoCommit to true, PG-15 set this value to false by default.


I hope my experience can help others.


--------------z1j704wqJn9NInie0rNI6YkP--