lundi 23 mars 2015

JDBC connection with mysql getting org.springframework.jdbc.CannotGetJdbcConnectionException

Just started using mysql, attempting to get jdbc connection but I am getting this error.



Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unknown database 'localhost')


Server is running and I am able to make queries into my database.


Here is what is in my jdbc.properties



jdbc.username=root
jdbc.password=password
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/localhost?profileSQL=true


Here is what is in the spring config file



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG
http://ift.tt/GArMu7 http://ift.tt/1bGeTcI">

<context:component-scan base-package="com.caveofprogramming.spring.test">
</context:component-scan>

<!--If creating a web project no need to do this, usually done on webapp server-->
<!--using class BasicDataSource in order to get the properties from the properties file-->
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="username" value="${jdbc.username}"></property>
</bean>

<context:property-placeholder
location="jdbc.properties" />

</beans>

Aucun commentaire:

Enregistrer un commentaire