pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedJDBC + PG-15 but not psql
5+ messages / 2 participants
[nested] [flat]
* JDBC + PG-15 but not psql
@ 2023-08-20 14:00 Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-21 18:51 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
0 siblings, 1 reply; 5+ messages in thread
From: Amn Ojee Uw @ 2023-08-20 14:00 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: JDBC + PG-15 but not psql
2023-08-20 14:00 JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
@ 2023-08-21 18:51 ` Dave Cramer <davecramer@postgres.rocks>
2023-08-21 23:41 ` Re: JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Dave Cramer @ 2023-08-21 18:51 UTC (permalink / raw)
To: Amn Ojee Uw <amnojeeuw@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
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.
>
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: JDBC + PG-15 but not psql
2023-08-20 14:00 JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-21 18:51 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
@ 2023-08-21 23:41 ` Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-22 12:31 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
0 siblings, 1 reply; 5+ messages in thread
From: Amn Ojee Uw @ 2023-08-21 23:41 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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.
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: JDBC + PG-15 but not psql
2023-08-20 14:00 JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-21 18:51 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
2023-08-21 23:41 ` Re: JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
@ 2023-08-22 12:31 ` Dave Cramer <davecramer@postgres.rocks>
2023-08-22 17:47 ` Re: JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Dave Cramer @ 2023-08-22 12:31 UTC (permalink / raw)
To: Amn Ojee Uw <amnojeeuw@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
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.
>>
>>
>>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: JDBC + PG-15 but not psql
2023-08-20 14:00 JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-21 18:51 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
2023-08-21 23:41 ` Re: JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-22 12:31 ` Re: JDBC + PG-15 but not psql Dave Cramer <davecramer@postgres.rocks>
@ 2023-08-22 17:47 ` Amn Ojee Uw <amnojeeuw@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Amn Ojee Uw @ 2023-08-22 17:47 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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.
>>
>>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2023-08-22 17:47 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-08-20 14:00 JDBC + PG-15 but not psql Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-21 18:51 ` Dave Cramer <davecramer@postgres.rocks>
2023-08-21 23:41 ` Amn Ojee Uw <amnojeeuw@gmail.com>
2023-08-22 12:31 ` Dave Cramer <davecramer@postgres.rocks>
2023-08-22 17:47 ` Amn Ojee Uw <amnojeeuw@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox