Unable to configure SB to use MySQL hosted BATCH_* tables - java

I am having some trouble configuring Spring to use BATCH_* tables hosted by MySQL.
I created the tables ok according to docs however it looks like the code is trying to get a sequence number using the Oracle flavour function.
The error I get is:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'BATCH_JOB_SEQ' in field list
But this is hiding the real problem. I debugged it and its trying to run this code:
select " + getIncrementerName() + ".nextval from dual";
Which is obviously Oracle dialect. I notice that there exists the correct incrementer in my environment here:
org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer()
but its calling
org.springframework.jdbc.support.incrementer.OracleMaxValueIncrementer()
I have setup my data source thus:
<bean id="springDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://10.252.205.5:3306/MASKNG" />
<property name="username" value="MASKNG" />
<property name="password" value="maskng" />
</bean>
Anyone have an ideas as this is a show stopper for us atm

Well, well, I really should RTM a little more...you just have to tell the jobRepository bean what type of DB you are using
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="springDataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="validateTransactionState" value="${jobRepository.validationTransactionState:true}" />
<property name="isolationLevelForCreate" value="${jobRepository.isolationLevelForCreate}" />
<!-- <property name="databaseType" value="oracle" /> -->
<property name="databaseType" value="mysql" />
<property name="tablePrefix" value="BATCH_" />
<property name="lobHandler" ref="lobHandler"/>
</bean>

Related

SEVERE: Error while registering Oracle JDBC Diagnosability MBean

Hi am facing below error using spring project and with oracle ojdbc14-1.4.jar
java version 1.8 and tomcat 7.0.37
When i execute the SQL directly in oracle its working fine not sure what I am missing in spring JDBC.
Also I had tried other oracle driver versions from maven
inside spring configuration file
<bean id="dataSourceDB" class="org.apache.tomcat.jdbc.pool.DataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="${database.url_revdbo}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="initialSize" value="${database.initialSize}" />
<property name="maxActive" value="${database.maxActive}" />
<property name="minIdle" value="${database.minIdle}" />
<property name="maxIdle" value="${database.maxIdle}" />
<property name="maxWait" value="${database.maxWait}" />
<property name="testWhileIdle" value="${database.testWhileIdle}" />
<property name="timeBetweenEvictionRunsMillis" value="${database.timeBetweenEvictionRunsMillis}" />
<property name="validationQuery" value="${database.validationQuery}" />
</bean>
<bean id="namedParameterJdbcTemplateDB"" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSourceDB" />
</bean>
inside java DAO layer
private String INSERT_REVENUE_DATA= "INSERT INTO table_test (BATCH_ID,status) values ( '1234','new')";
#Autowired
#Qualifier("namedParameterJdbcTemplateDB")
private NamedParameterJdbcTemplate namedParameterJdbcTemplateDB;
Map<String, Object> paramMap = new HashMap<>();
//paramMap.put("field1", "1111");
//paramMap.put("field2", "new");
namedParameterJdbcTemplateRevport.update(INSERT_DATA, paramMap);
oracle.jdbc.driver.OracleDriver registerMBeans
SEVERE: Error while registering Oracle JDBC Diagnosability MBean.
javax.management.MalformedObjectNameException: Invalid character '\n' in value part of property
at javax.management.ObjectName.construct(ObjectName.java:618)
at javax.management.ObjectName.<init>(ObjectName.java:1382)
at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:303)
at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:213)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:209)
You get this error :
javax.management.MalformedObjectNameException:
Invalid character '\n' in value part of property
because you have two quotes in the property :
<bean id="namedParameterJdbcTemplateDB""
//------------------------------------^^
You have to use just one

JAVA + PostgreSQL + Spring

I want to use Spring to connect to my local PostgreSQL db. I don't know if it is possible, cause I didn't find any tutorials for this. So is it possible? If yes, please explain me where can I find some fine tutorial. If no, how can I do it? I know I can make it via postgresql jdbc, but I want to do it like in real company.
Of course you can. The database vendor is immaterial. Java hides database details using JDBC.
Here is a Spring tutorial that shows you how to do it in 15 minutes or less.
First you need to create a spring project from https://start.spring.io/ and add postgresql to its dependencies. You will then see it build up in your pom.xml file. Then you have to enter the information of the postgresql database you want to connect to in the application.yml file.
Here is my example.
applicationContext.xml :
<!-- the setting msg -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/database.properties</value>
</list>
</property>
</bean>
<!-- PostgreSQL datasource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- ibatis client -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:config/SqlMapConfig.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

Can't connect to mysql in centos

I use Spring+Mybatis and try to connect mysql server 5.1 in Centos.
The Connection of mysqldatabase is ok and there is no problem when I'm testing with Test Class.
And There is no problem when connecting MYSQL5.5 in Window Server with same config.
In Connecting to MYSQL5.1 in Centos,
When my web application project make a select query, an exception is occurred.
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nmnl.USR' doesn't exist
How can I solve?
This is config in spring-beans.xml.
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<util:properties id="SQL_ERROR_CODE" location="classpath:SQL_ERROR_CODE.properties" />
<util:properties id="APPLICATION_CONFIG" location="classpath:APPLICATION_CONFIG.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.99:3306/nmnl?useUnicode=yes&characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlmap-config.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
Please check whether table USR exist in nmnl database or not. Because exception says table USR not exists in nmnl.
Yeah. I got it.
When i restore database with query,My query is CREATE USR.
I remove this char ` and restore back.
And I changed all table names to UPPER case.
I soled. MySQL in linux has case-sensitive. There is only can choose upper or lower. My queries in mybatis sql map are both lower and upper. So i was changed all to UPPER cases.

Converted JNDI name [java:comp/env/***] not found before reading the properties file

Good Mornig.
I have an application in tomcat 8, java 1.7, Spring 3.2.2 and primefaces 5.0. When the application starts, it shows the next debug message in console:
Looking up JNDI object with name [java:comp/env/etl.csv.token]
localhost-startStop-1: org.springframework.jndi.JndiLocatorDelegate
Converted JNDI name [java:comp/env/etl.csv.token] not found
But the key isn't in the JNDI context. It is in a properties file. The application works fine and takes the property from the properties file, but i can't understand why spring is trying to find the property in the JNDI context
The properties file is like this:
database.driverClassName=org.postgresql.Driver
database.initialSize=3
database.maxActive=15
database.maxIdle=10
database.minIdle=3
database.maxWait=10000
etl.csv.token=,
And its properties are used like this:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="initialSize" value="${database.initialSize}" />
<property name="maxActive" value="${database.maxActive}" />
<property name="maxIdle" value="${database.maxIdle}" />
<property name="maxWait" value="${database.maxWait}" />
<property name="minIdle" value="${database.minIdle}" />
<property name="testOnBorrow" value="true" />
<property name="validationQuery" value="SELECT CURRENT_TIMESTAMP" />
<property name="removeAbandoned" value="true" />
</bean>
For all properties, the behaviour is the same. I would like that message does not appear
Sorry for the english, is not my native language
Any help will be apreciated.

How to call rest API(Start Process Instance) for Acitviti in JAVA

This is my java code.
ProcessEngines.getDefaultProcessEngine().getRuntimeService().startProcessInstanceByKey("myclcprocess");
server Details:
Schema Details: Server HMECD000046v,
Schema Name: activiti,
Credentials- root, root,
Proc Definition ID- 'myclcprocess:4:7907'
This is my first simple program. I'm getting NullPointerException. Please any one help me how to configure?. and how to invoke the process?.
need to create Activiti.cfg.xml. In that file need to configure the data source details
Example:
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration" >
<!-- Database configurations -->
<property name="jdbcUrl" value="jdbc:mysql://localhost/activiti" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
<property name="defaultAutoCommit" value="false" />
</bean>
references:
http://krishnasblog.com/2012/05/07/4/
http://bpmn20inaction.blogspot.in/2010/12/activiti-spring-integration-example.html

Categories