braghome (4) [Avatar] Offline
#1
For someone learning this subject new, it would help help a lot to have access to datasource configuration examples complete for chapters 1 and 2. So a newbee can better understand by looking at database tables and data. Chapter one does even have a main driver class.
With in memory database your examples start to look like a blackbox.
braghome (4) [Avatar] Offline
#2
Re: Need configuration for mysql
a mysql based complete configuration would suffice for chapters 1 and 2.
braghome (4) [Avatar] Offline
#3
Re: Need configuration for mysql
Basically I am trying to find the equivelent of h2 here:

Right now I have nothing inside.

public class LaunchDatabaseAndConsole {

public static void main(String[] args) {
new ClassPathXmlApplicationContext(
"/com/apple/webapp/batch-infrastructure-context.xml",
"/com/apple/webapp/root-database-context.xml");

}

}
braghome (4) [Avatar] Offline
#4
Re: Need configuration for mysql
I have trying this ...

public class LaunchDatabaseAndConsole {

public static void main(String[] args) {
new ClassPathXmlApplicationContext(
"/com/apple/webapp/batch-infrastructure-context.xml",
"/com/apple/webapp/root-database-context.xml");

// The newInstance() call is a work around for some
// broken Java implementations
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();

} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

}

}

get this:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/batch/core/schema-mysql.sql]: CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_NAME VARCHAR(100) NOT NULL, JOB_KEY VARCHAR(32) NOT NULL, constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) ) ENGINE=InnoDB
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:28smilie
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.apple.webapps.batch.LaunchDatabaseAndConsole.main(LaunchDatabaseAndConsole.java:smilie
Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/batch/core/schema-mysql.sql]: CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_NAME VARCHAR(100) NOT NULL, JOB_KEY VARCHAR(32) NOT NULL, constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) ) ENGINE=InnoDB
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 12 more
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [org/springframework/batch/core/schema-mysql.sql]: CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_NAME VARCHAR(100) NOT NULL, JOB_KEY VARCHAR(32) NOT NULL, constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) ) ENGINE=InnoDB
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:183)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:120)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:80)
... 14 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'batch_job_instance' already exists
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:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:402smilie
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:174smilie
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1665)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:169)
... 16 more
arnaud.cogoluegnes (73) [Avatar] Offline
#5
Re: Need configuration for mysql
the error message is clear:

> Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'batch_job_instance' already exists

You must have launched the java program several times, the DB is persistent and the tables cannot be re-created.

I created a new Github repo with the last code samples and a "chapter-02-mysql" branch with a workable MySQL configuration.

The following commit will help you to spot the differences: https://github.com/acogoluegnes/Spring-Batch-in-Action/commit/3b3977a12ef0d83703d09d6d1597ed20112d6c7d

Focus on the pom.xml, connect-database-context.xml, and root-database-context.xml files for the data source configuration.

We assume the reader has some basic knowledge of Java (thus JDBC) and Spring, so we skip things like data source configuration if they don't have anything special (otherwise the book would be much longer or couldn't cover advanced Spring Batch topics).

Hope the git branch will help you and thanks for your interest and feedback on the book!

Arnaud
artjureallove (11) [Avatar] Offline
#6
Re: Need configuration for mysql
แต่ละแห่งยังได้เปิดคำแนะนำ ระดับมาตรฐานชั้นนำครบครันด้วยความที่เราเป็นผู้ชำนาญด้าน ผลบอล ด้วยแนวทางที่ทันทีทันใดและปลอดภัย ที่ทำให้คุณได้รับเงินโดยทันทีทันใจตลอด 24 ชม. ผู้ได้รับอนุญาตผสมกิจการ คาสิโนโดยไม่ผิดพลาดตาม กฎหมายของประเทศกัมพูชา casino online พร้อมกับผลประโยชน์ที่ได้รับเต็มจำนวน