Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide
this week in the
Programmer Certification
forum!
Post Reply
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
JDBC and Relational Databases
Integration test on JDBC (No Hibernate !) and Spring AbstractTransactionalJUnit4SpringContextTests
Stephane Eybert
Ranch Hand
Posts: 34
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I'm trying to set up an integration
test
against a MySql database with a pure
JDBC
dao, that is, NOT using Hibernate or any ORM tool.
My base abstract test class uses the AbstractTransactionalJUnit4SpringContextTests class so as to have tests that roll back.
public abstract class AbstractDaoTest extends AbstractTransactionalJUnit4SpringContextTests { }
Spring requires a transactionManager bean which I provide.
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean>
But I get an exception.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1205) at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1197) at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4954)
Do I need to provide some connection pooling ?
Is there any way to do it with a Spring bean ?
Kind Regards,
Stephane
Rob Spoor
Sheriff
Posts: 22849
132
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're calling setAutoCommit on a Connection that's already closed.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Stephane Eybert
Ranch Hand
Posts: 34
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How come is the connection closed ?
public void insert(GInnAdresse gInnAdresse) throws SesamSqlException { String sql = "insert into g_inn_adresse values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, null);"; Connection connection = null; try { connection = dataSource.getConnection(); connection.setAutoCommit(false); PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, gInnAdresse.getId()); preparedStatement.setString(2, gInnAdresse.getOpprettet()); preparedStatement.setInt(3, gInnAdresse.getAdr_id()); preparedStatement.setString(4, gInnAdresse.getNbr_id()); preparedStatement.setInt(5, gInnAdresse.getKun_kundenr()); preparedStatement.setInt(6, gInnAdresse.getAns_id()); preparedStatement.setString(7, gInnAdresse.getKde_id()); preparedStatement.setString(8, gInnAdresse.getKua_k_adr_type()); preparedStatement.setString(9, gInnAdresse.getLnd_kode()); preparedStatement.setString(10, gInnAdresse.getPos_postnr()); preparedStatement.setString(11, gInnAdresse.getAdr_adr1()); preparedStatement.setString(12, gInnAdresse.getAdr_adr2()); preparedStatement.setString(13, gInnAdresse.getAdr_tlf()); preparedStatement.setString(14, gInnAdresse.getAdr_fax()); preparedStatement.setString(15, gInnAdresse.getAdr_utl()); preparedStatement.setString(16, gInnAdresse.getAdr_endret_dato()); preparedStatement.executeUpdate(); connection.commit(); preparedStatement.close(); } catch (SQLException e) { throwCustomException(connection, e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { ExceptionUtils.printRootCauseStackTrace(e); } } try { connection.setAutoCommit(true); } catch (SQLException e) { ExceptionUtils.printRootCauseStackTrace(e); } } }
Rob Spoor
Sheriff
Posts: 22849
132
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Because line 32 comes before line 38.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Stephane Eybert
Ranch Hand
Posts: 34
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Fair enough :-) Thanks !
Rob Spoor
Sheriff
Posts: 22849
132
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're welcome
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Mysql driver fails on connection
Error while using DriverManager to connect to MySQL DB.
JDBC throws exception on java app detach from console
JBM-Tables not created.
Problem with MySql Connections in servlet application
More...