spring Ibatis Mysql ReplicationDriver - java

i had use the spring3.1 ibatis2.x and mysql5.5.
then i wanna use the replication driver .
my code is:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.ReplicationDriver" />
<property name="url" value="jdbc:mysql:replication://192.168.1.160:3306/test,192.168.1.160:3306/test" />
<property name="username" value="root" />
<property name="password" value="root" />
.....
then:
Caused by: org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (Must specify at least one slave host to connect to for master/slave replication load-balancing functionality)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:224)
at $Proxy50.getMetaData(Unknown Source)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:285)
... 50 more
Caused by: java.sql.SQLException: Must specify at least one slave host to connect to for master/slave replication load-balancing functionality
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.NonRegisteringReplicationDriver.connect(NonRegisteringReplicationDriver.java:107)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
so how to make the ibatis to support replication

Try this
<property name="url" value="jdbc:mysql:replication://192.168.1.160:3306,192.168.1.160:3306/test" />
The format is : master,slave1,slave2
Don't why you taking same server for load balancing.

Related

SSl over Informix JDBC doesn't work under JBOSS 7

I want to use my Informix JDBC application over SSL. The DBMS is Informix IBM 11.70.
I'm using a spring-config.xml file in which I declare the datasource bean:
<!-- Data source -->
<bean id="dataSource" class="com.sopra.datasource.CustomDataSource" init-method="init"
destroy-method="close">
<property name="url" value="${url}" />
<property name="driverClassName" value="${driverClassName}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="removeAbandoned" value="true" />
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
</bean>
The problem is that when I deploy my application in Tomcat 7 everything goes well (both TCP and SSL mode), however, when I deploy it in JBOSS 7.1 the SSL connexion mode to the Informix database doesn't work!
When it comes to debugging, the only information that I have is the following :
Application side:
Caused by: com.informix.asf.IfxASFException: Attempt to connect to database server (my_server_ssl) failed.
at com.informix.util.IfxErrMsg.getLocIfxASFException(IfxErrMsg.java:751) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.openSocket(Connection.java:1864) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.<init>(Connection.java:427) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.jdbc.IfxSqliConnect.<init>(IfxSqliConnect.java:1416) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
... 47 more
Caused by: java.lang.NullPointerException
at com.informix.asf.Connection.getEnabledSSLProtocols(Connection.java:2242) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.openSocket(Connection.java:1805) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
... 49 more
Thanks in Advance.
This was due to a defect in the 4.10.7 version of the driver. Try upgrading to either 4.10.8 or 4.10.9 versions. They can be found via maven or through your IBM download site.
Gradle
compile group: 'com.ibm.informix', name: 'jdbc', version: '4.10.9'
Maven
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.10.9</version>
</dependency>

JMS 112 Invalid connection using spring ds

I'm using a spring datasource and is unable to connect to Oracle AQ Queue.
Connection connection = null;
AQSession aqSess = null;
connection = ds.getConnection();
connection.setAutoCommit(false);
DataSourceUtils.getTargetConnection(connection);
Class.forName("oracle.AQ.AQOracleDriver");
aqSess = AQDriverManager.createAQSession(connection);
aqSession = aqSess;
But still get this: oracle.jms.AQjmsException: JMS-112: Connection is invalid any tips would be appreciated.
<bean id="myId" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#myIpAddress:dev"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="2"/>
<property name="maxIdle" value="8"/>
<property name="maxActive" value="30"/>
<property name="maxWait" value="60000"/>
</bean>
AQException: oracle.AQ.AQException: JMS-112: Connection is invalid
at oracle.AQ.AQDriverManager.createAQSession(AQDriverManager.java:193)
I fixed my problem using the following code:
OracleConnection oracleConnection = connection.unwrap(OracleConnection.class);
Recording it here as an answer in case others find this question when having a similar problem.
Oracle AQ doesn't match with BasicDataSource
useOracleDataSource instead
but if you want to use BasicDataSource:
In many application server environments the JDBC connection is wrapped
in an implementation specific class that delegates to the underlying
native JDBC connection. Oracle's AQ connection factory needs the
native Oracle connection and will throw an "oracle.jms.AQjmsException:
JMS-112: Connection is invalid" exception if the connection is wrapped
by a foreign class. To solve this problem you can specify a
NativeJdbcExtractor that can be used to unwrap the connection. Spring
provides a number of implementations to match the application server
environment. Here is an example for specifying a NativeJdbcExtractor.
<orcl:aq-jms-connection-factory id="connectionFactory"
use-local-data-source-transaction="true"
native-jdbc-extractor="dbcpNativeJdbcExtractor" 1
data-source="dataSource" />
<bean id="dbcpNativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="dbcpDataSource" 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>
https://docs.spring.io/spring-data/jdbc/old-docs/2.0.0.BUILD-SNAPSHOT/reference/html/orcl.streamsaq.html

Can't connect to PostgreSQL with JDBC driver

I have my Spring MVC app.
dispatcher-servlet.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/dailyjob"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
When my app is trying to connect to the database, I get the exception
Caused by: org.postgresql.util.PSQLException: ?????: ????????????
"root" ?? ?????? ???????? ??????????? (?? ??????) at
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:398)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:173)
at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at
org.postgresql.jdbc2.AbstractJdbc2Connection.(AbstractJdbc2Connection.java:136)
at
org.postgresql.jdbc3.AbstractJdbc3Connection.(AbstractJdbc3Connection.java:29)
at
org.postgresql.jdbc3g.AbstractJdbc3gConnection.(AbstractJdbc3gConnection.java:21)
at
org.postgresql.jdbc4.AbstractJdbc4Connection.(AbstractJdbc4Connection.java:31)
at
org.postgresql.jdbc4.Jdbc4Connection.(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393) at
org.postgresql.Driver.connect(Driver.java:267) at
java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:208) at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:153)
at
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 46 more
If I'm trying to connect to mysql with
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/dailyjob"
p:username="root"
p:password="root" />
everything is OK!
My app has jdbc drivres for both (mysql and postgres).
I am also uses postgresql with Java earlier I also facing the same problem,
I work around and found the solution, could you please try with adding below statement to bean "dataSource"
<property name="defaultAutoCommit" value="false"/>

Java program to connect mysql using socket=/opt/zimbra/db/mysql.sock

I have fetched my mail from gmail account to local zimbra machine and which is stored in mysql database, which run mysql on 7306 port and /opt/zimbra/db/mysql.sock.
Now, I would like to access all those record via java program.
I have used Spring with Java program using zimbra java version 1.7.0_07-b10
Here is configuration in xml file ..
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://172.18.100.117:7306/mboxgroup8?socket=/opt/zimbra/db/mysql.sock"/>
<property name="username" value="zimbra"/>
<property name="password" value="Zy"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="5"/>
<property name="maxWait" value="60000"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="60"/>
<property name="logAbandoned" value="true"/>
<property name="validationQuery" value="Select 1"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
</bean>
When I tried to connect via program, it gives me below error...
getMails- 59- Exception in getMails at Manager:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:182)
at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:219)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:266)
at com.cashEmail.core.dao.MailItemDAOImpl.selectByExampleWithBLOBs(MailItemDAOImpl.java:86)
at com.cashEmail.manager.CashManager.getMails(CashManager.java:48)
at com.cashEmail.core.service.CashService.getCashEmail(CashService.java:77)
at com.cashEmail.resource.CashResource.getEmails(CashResource.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

How should I write JDBC url for Oracle with LDAP and two LDAP servers?

I have an Oracle database with LDAP, and can connect by writing smth like:
jdbc:oracle:thin:#ldap://oid0.wow.com:666/chost,cn=OracleContext,dc=wow,dc=com
But this is not failover (we have another server with Oracle LDAP - oid1.wow.com:666)
How can I use both servers to reach failover?
I found this solution, but it doesn't work:
java.sql.SQLException: Io exception: Invalid LDAP URL specified
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:257)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:389)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:454)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
It was a driver!
Throw debugging I've found antother issue with String.concat() NPE
Our driver (com.oracle ojdbc14 10.2.0.4.0 - found in MVN repo) doesn't suppor two o more URL's.
When I downloaded driver from Oracle site (10.1.0.5 'ojdbc14_g') all start work fine.
All of this looks strange because 10.1.0.5 seems to be the last version of Oracle JDBC drivers on official site (for Oracle 10 of course).
Here is! Failover dataSource bean:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!--common dataSource props -->
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value="jdbc:oracle:thin:#ldaps://oid0.wow.com:666/chost,cn=OracleContext,dc=wow,dc=com ldaps://oid1.wow.com:666/chost,cn=OracleContext,dc=wow,dc=com"/>
<property name="overrideDefaultUser" value="useruser"/>
<property name="overrideDefaultPassword" value="strongpassword"/>
<!-- special c3p0 props -->
<property name="minPoolSize" value="1"/>
<property name="maxPoolSize" value="10"/>
<property name="maxStatements" value="10"/>
<property name="breakAfterAcquireFailure" value="false"/>
<property name="acquireRetryAttempts" value="5"/>
<property name="testConnectionOnCheckin" value="true"/>
<property name="properties">
<props>
<prop key="oracle.net.ldap_loadbalance">OFF</prop>
</props>
</property>
</bean>

Categories