Spring database cannot get connection - Error querying database - CannotGetJdbcConnectionException - dbcp.SQLNestedException

I encountered Error querying database during sm integration today.

It is found that it is a fault that the database cannot be connected. You can find the problem according to the following steps.

1. It turned out that it was only the properties of the data source that introduced the file, and jdbc must be added before the el expression ( where there are often problems )

The reason is:

Spring4.0.4 official document data source configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  
  <!-- Scans within the base package of the application for @Components to configure as beans -->
  <context:component-scan base-package="org.springframework.docs.test" />
  
  <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>

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

</beans>

So configure the data source in your db.properties or applicationContext.xml, you must add jdbc. The form is jdbc.username.

Then after it is correct, it is still saved, then

1. Whether your db.properties file is configured correctly useUnicode=true&characterEncoding=UTF-8 means that the encoding you set is utf-8 to ensure that it is consistent with the database to prevent garbled characters

2. Check whether your spring/applicationContext-dao.xml is configured with the data source and whether it is configured correctly

3. Is your connection name the same as what you configured in db.properties

4. Is the service on your computer turned on?

5. Check whether your database name exists, or whether the table exists



Original solution reference:  https://www.cnblogs.com/zhoumingming/p/5401144.html 

Original solution reference:  https://www.cnblogs.com/panxuejun/p/5850599.html

 

 

 




 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324603663&siteId=291194637