springboot使用Mysql和oracle两个数据源案例

boot里使用Mysql, oracle两个数据源来实现同步,有没有实现两个数据源得案例参考一下啊,谢谢了

#include <iostream>
using namespace std;
int main()
{
    char str[1024];
    cin.get(str, 1024);
    if (str[0] >= '0' && str[0] <= '9')
    {
        cout << "no";
        return 0;
    }
    for (int i = 0; i < strlen(str); i++)
    {
        if (!(str[i] == '_' || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= '0' && str[i] <= '9')))
        {
            cout << "no";
            return 0;
        }
    }
    cout << "yes";
    return 0;
}

参考:https://blog.csdn.net/qq_32629789/article/details/89554196

http://blog.majiameng.com/article/2711.html

import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/*

  • 配置多数据源 */

public class DynamicDataSource extends AbstractRoutingDataSource{

 public static final String mySqlDataSource= "mySqlDataSource";  

 public static final String sqlServerDataSource = "sqlServerDataSource";  
 //本地线程,获取当前正在执行的currentThread  
 public static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();   

 public static void setCustomerType(String customerType) {  

// System.out.print("切换数据源:"+customerType);
contextHolder.set(customerType);

 }  

 public static String getCustomerType() {  
     return contextHolder.get();       
 }  

 public static void clearCustomerType() {  
     contextHolder.remove();  
 }  

 @Override  
 protected Object determineCurrentLookupKey() {
     String dataSource = contextHolder.get();
     if(dataSource == null){
         dataSource = sqlServerDataSource;
     }
     return dataSource;    
 }

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    // TODO Auto-generated method stub
    return null;
}

}


配置多数据源,比如mysql和SQLserver,需要用的时候做切换

做过通过入参来路由到不同的数据源,现在搞忘了,要看看以前的代码