Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java.sql.SQLException: You cannot set autocommit during a managed transaction!

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Friends,
I'm using a Datasource connection configured in xxx-ds.xml of Jboss Server. And used method setAutoCommet(false) after getting connection.Due to this i received the error of "java.sql.SQLException: You cannot set autocommit during a managed transaction!"

My datasource file is
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:mysql://localhost:3306/mspdb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password></password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

And My Connection Code is


String dsName = dataSource;
try {
/* get data source by lookup in initial context */
ds = (DataSource)MSPUtility.getInitialContext().lookup(dsName);
conn = ds.getConnection();
/*set AutoCommited False*/
conn.setAutoCommit(false);

}
catch (Exception e) {
e.printStackTrace();
System.out
.println("[Error][MSPDal]: Falied while getting datasource connection: "
+ dsName);

}

Can you please help me to resolved this issue.

Thanks
Vijay Aneraye
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
don't call that method.
It there is already a transaction provided by JBoss, you don't need to manage the autocommit property.
 
Vijay Aneraye
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello David,
Thanks for replay.
Actually I want to do that trasaction manualy. Then what changes I need to do.
I am using ejb3.0 stateless session bean.

Thanks
Vijay Aneraye
 
Vijay Aneraye
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello David,
Thanks for replay.
Actually I want to do that trasaction manualy. Then what changes I need to do.
I am using ejb3.0 stateless session bean.

Thanks
Vijay Aneraye
 
author & internet detective
Posts: 40200
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'll close this copy so we can continue discussion in one place
 
Everybody's invited. Even this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic