<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="????????????????????" />
<property name="url"
value="???????????????????????"/>
<property name="username" value="root" />
<property name="password" value="" />
</bean>
I am not able to figure out what should go in driver class name value and url vale. I have downloaded Oracle sql developer and oracle 11 g.But i am not sure how to configure it to my java application
Driver class name:- oracle.jdbc.driver.OracleDriver
URL :- jdbc:oracle:thin:#(hostname):(port number):(database name)
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:#(hostname):(port number):(database name)"/>
<property name="username" value="root" />
<property name="password" value="" />
</bean>
Your qustion is not clear if you are using Spring framework there are two type of
Data source handling technique
Method 1 you need to configure data source in your application server
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/OracleDS" />
<property name="cache" value="false"/>
<property name="lookupOnStartup" value="false"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
Method 2
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#127.0.0.1:1521:OMQA" />
<property name="username" value="root" />
<property name="password" value="password" />
</bean>
Related
I need to use 2 version of DB2Driver for my application. I am using spring to define dataSources. The path of two Libs are the same, the first dataSource needs driver version2 and second one needs version3. Is there any way to solve this problem?
<bean id="DataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="yyy"/>
<property name="username" value="yyy"/>
<property name="password" value="yyy"/>
</bean>
<bean id="DataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="url" value="xxx"/>
<property name="username" value="xxx"/>
<property name="password" value="xxx"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="10"/>
<property name="minIdle" value="1"/>
<property name="maxWait" value="3000"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="numTestsPerEvictionRun" value="50"/>
<property name="minEvictableIdleTimeMillis" value="10000"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://xxx.xx.xxx.xxx:3306/vod6?autoReconnect=true" />
<!-- <property name="url" value="jdbc:mysql://xxx.xx.xxx.xxx:3306/vod2?autoReconnect=true" /> -->
<property name="username" value="voddb" />
<property name="password" value="vod#123" />
</bean>
above config xml working fine .
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${mysql.driverClassName}" />
<property name="url" value="${mysql.url}" />
<property name="username" value="${mysql.username}" />
<property name="password" value="${mysql.password}" />
</bean>
When I am trying to configure jdbc.property and configure them throwing error out of memory
Can you please explain what i am missing?
mysql.database=MYSQL
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://xxx.xx.xxx.xxx:3306/vod?autoReconnect=true
mysql.username=voddb
mysql.password=vod#123
mysql.initialSize=4
mysql.maxActive=30
property file
Please confirm whether the placeholder is mentioned correctly in applicationContext.xml file
<context:property-placeholder location="classpath*:catalina.properties" ignore-unresolvable="true"/>
If this is configured correctly please try removing mysql.initialSize=4 mysql.maxActive=30 from properties file and test, this may be thr root cause. Because this is the additional property you have mentioned in properties file
You can try configuring these maxActive,initialSize values in xml itself as property.
<property name="removeAbandonedTimeout" value="180"/>
<property name="removeAbandoned" value="true"/>
<property name="logAbandoned" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="5000"/>
<property name="minEvictableIdleTimeMillis" value="900000"/>
<property name="maxActive" value="20"/>
<property name="maxIdle" value="4"/>
I have deployed two Spring roo application on Tomcat 7 server both have database connection while hitting any service of application I am getting below exception
Cannot create JDBC driver of class 'org.postgresql.Driver' for connect URL 'postgres://username:password#localhost:5432/db'
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:278)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
Please find below database base configuration
Application 1
application-Context.xml
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="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="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="validationQuery" value="SELECT version();"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
Application 1. Database.properties
database.driverClassName=org.postgresql.Driver
database.url=jdbc\:postgresql\://localhost\:5432/db
database.username=username
database.password=password
Application 2
application-Context.xml
<bean class="java.net.URI" id="dbUrl">
<constructor-arg value="postgres://username:password#localhost:5432/db"/>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="#{ 'jdbc:postgresql://' + #dbUrl.getHost() + ':' + #dbUrl.getPort() + #dbUrl.getPath() }"/>
<property name="username" value="#{ #dbUrl.getUserInfo().split(':')[0] }"/>
<property name="password" value="#{ #dbUrl.getUserInfo().split(':')[1] }"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="validationQuery" value="SELECT version();"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<util:properties id="regex.properties" location="classpath:META-INF/spring/regex.properties"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
Please advice how can I resolve my Problem..
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/db" />
<property name="user" value="user" />
<property name="password" value="pass" />
<!-- pool sizing -->
<property name="initialPoolSize" value="3" />
<property name="minPoolSize" value="6" />
<property name="maxPoolSize" value="25" />
<property name="acquireIncrement" value="3" />
<property name="maxStatements" value="0" />
</bean>
I used this and it works
Postgres extensions are installed in public schema.
Set the search path for the app-specific schema on the DBCP datasource the following way:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?searchpath=mySchema,public;?ApplicationName=${app.name}"/>
<property name="connectionProperties" value="currentSchema=mySchema;"/>
<property name="username" value="user"/>
<property name="password" value="pw"/>
<property name="defaultAutoCommit" value="false"/>
<property name="maxActive" value="6" />
</bean>
But somehow I cannot use extensions installed in this public schema without qualifying them like "public.hstore".
Found the solution - JDBC driver does not know the searchpath property in the URL. But this has been nowhere reported :-(
Instead currentSchema is given to driver which is then mapped to native Postgres searchpath (thus probably overwriting the default one there with public included). Not intuitive!
So the solution looks like this:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?ApplicationName=${app.name}"/>
<property name="connectionProperties" value="currentSchema=mySchema,public;"/>
<property name="username" value="user"/>
<property name="password" value="pw"/>
<property name="defaultAutoCommit" value="false"/>
<property name="maxActive" value="6" />
Spring3, Hibernate, MySQL: I am working on my first project, can some one please show me how to change the following code to add database pooling? thanks
applicationContext-security-JDBC.xml
<beans:bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${database.driver}" />
<beans:property name="url" value="${database.url}" />
<beans:property name="username" value="${database.user}" />
<beans:property name="password" value="${database.password}" />
</beans:bean>
jdbc.properties
database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://127.0.0.1/db_mytest
database.user=root
database.password=
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true
thanks.... again
I suggest you to use commons-dbcp. You have to download the jar and add it to the WEB-INF/lib directory (if not already included in your application server). This is your new applicationContext.xml with some default parameters that you should change as you wish:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="timeBetweenEvictionRunsMillis" value="300000" />
<property name="numTestsPerEvictionRun" value="6" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="initialSize" value="3" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="5000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxOpenPreparedStatements" value="100" />
</bean>
Hope this helps.
You don't specify what you are running your application on. Many application servers have their own connection pooling implementation that you can tap into. I've used Tomcat's DBCP in the past - was quite easy to set up.