Q:org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: socket creation error<br />at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:238)<br />at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374)<br />at org.springframework.test.AbstractTransactionalSpringContextTests.startNewTransaction(AbstractTransactionalSpringContextTests.java:387)<br />at org.springframework.test.AbstractTransactionalSpringContextTests.onSetUp(AbstractTransactionalSpringContextTests.java:217)<br />at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:101)<br />at junit.framework.TestCase.runBare(TestCase.java:128)<br />at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)<br />at junit.framework.TestResult$1.protect(TestResult.java:106)<br />at junit.framework.TestResult.runProtected(TestResult.java:124)<br />at junit.framework.TestResult.run(TestResult.java:109)<br />at junit.framework.TestCase.run(TestCase.java:120)<br />at junit.framework.TestSuite.runTest(TestSuite.java:230)<br />at junit.framework.TestSuite.run(TestSuite.java:225)<br />at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)<br />at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)<br />at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)<br />at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)<br />at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)<br />at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)<br />Caused by: java.sql.SQLException: socket creation error<br />at org.hsqldb.jdbc.Util.sqlException(Unknown Source)<br />at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)<br />at org.hsqldb.jdbcDriver.getConnection(Unknown Source)<br />at org.hsqldb.jdbcDriver.connect(Unknown Source)<br />at java.sql.DriverManager.getConnection(DriverManager.java:582)<br />at java.sql.DriverManager.getConnection(DriverManager.java:154)<br />at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:174)<br />at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:165)<br />at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)<br />at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)<br />at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:200)<br />... 18 more
A:多數是因為資料庫沒有開啟的緣故!
若使用的HSQLDB的話,應首先開啟HSQLDB的server,如server.bat
附server.bat內容:
java -classpath ../WebContent/WEB-INF/lib/hsqldb.jar org.hsqldb.Server -database test