Project needs to get data from other sites, because it is a temporary addition to the requirements, at the beginning of the project did not expect to need multiple data sources
So Baidu a bit, found that only need to change the spring applicationcontext.xml files and write three tool classes can be a perfect implementation
Applicationcontext.xml
Dataso
Sometimes you need to connect to multiple databases, data sources are inconsistent and need to be configured.1, configuration XML. A data source, a template.......Multiple configurations can be repeated.The corresponding class is inherited Basicdatasource. and encryption operations are possible.2, public class.@Autowiredprotected JdbcTemplate JdbcTemplate;@Autowi
save the database file to the project's debug folder, through the program to automatically get the database file path function, the code is as follows:1 CString szpath;2GetModuleFileName (Null,spath.getbuffersetlength (max_path+1), MAX_PATH); 3 Szpath.releasebuffer ();4 intNPos;5npos=szpath.reversefind (' \ \ ');6Szpath=Szpath.left (nPos);7CString Szfile = spath +"\\image.mdb"; 8 Charszatr[ the]; 9sprintf (Szatr,"dsn=%s! dbq=%s! defaultdir=%s!!","MyImage", Szfile,szpath); Ten intNlen; OneNlen =
spring2.0 later added abstractroutingdatasource this thing provides a dynamic switching data source.
Abstractroutingdatasource inherits the Abstractdatasource,abstractdatasource is a subclass of Javax.sql.DataSource.
Here is an example of a dynamically switching data source:
1. configuration file configuration in Spring.xml
2. Creating an implementation class for dynamically switching
service, injecting the Servie into the controller, interacting with the server
In actual projects, the service also needs to interact with the server.
var app = Angular.module ("App", []);
App.service ("Todoservice", Function ($q, $timeout) {
This.gettodos = function () {
var d = $q. Defer ();
Simulates a request
$timeout (function () {
d.resolve ([
{item: ", Done:false},
...
])
},3000);
return d.promise;
}
This.addtodo = function (item) {
This.todos.push ({item:item, done:false});
}
)
/utilhttp://www.springframework.org/schema/util/spring-util-4.0.xsd">class= "Com.alibaba.druid.pool.DruidDataSource"Destroy-method= "Close" > class= "Com.alibaba.druid.pool.DruidDataSource"Destroy-method= "Close" > class= "Com.jdd.ds.MultipleDataSource" > class= "Org.mybatis.spring.SqlSessionFactoryBean" > 8, to here and spring-related configuration is basically finished, in fact, after the configuration of MySQL master and slave replication, is the operation of the write library is synchronized
JBoss is a very powerful Java EE application Server, but this powerful feature also brings complexity. The author of this article, Marcus Zarra, analyzes how to configure multiple databases and data sources in JBoss.
Configure a data source
The default setup process for JBoss is a total of three configuration options: all, default, and minimum (minimal). If you
not pass the connection is discarded and a connection is reassigned. The default is FalseNBSP; N test-after-use If set to True connection will be tested with the House-keeping-test-sql set before closing (putting back the connection pool) if the test does not pass connection will be discarded. The default value is FalseNBSP; ? Unlike other connection pooling features, Proxool does not provide a set method. All features have to be info.setproperty ("Proxool.jmx", "false"), NBSP; ? The setting o
Transactionstatus object
In the need of a consistency processing database, Try...catch.
Normal process, Platformtransaction.commit (transactionstatus), when an exception occurs, call Platformtransaction.rollback (Transactionstatus)
How the 2,spring Platformtransactionmanager is associated with the underlying data sourceIn the opening section, using a JDBC data source, the transaction is also a
Jndi The default address for the Wildfly service Management console is Http://127.0.0.1:9990/console, and after linking because there are no users, you will be prompted to add users through Add-user.bat. Just follow the prompts to create the user and then log in to the console with the user you created. There is a problem here, when creating the data source, you need to select the JDBC driver deployed in the system, then you need to put the driver ja
The following are the steps for a specific configuration:1. First configure the Jndi data source under Tomcat. The specific storage directory Apache-tomcat-7.0.59\conf\catalina\localhostOsh.xml(2) The database driver jar is placed in the Lib directory in the Tomcat installation file.(3) Spring Applicationcontext.xml is configured in DataSource:Note that java:comp/env must be added to the Vlaue attribute, followed by the name of resource in servers(4)
toOrg.apache.tomcat.dbcp.dbcp.BasicDataSourceFactoryThis connection, the anti-compilation look, the discovery is in this to get the user name password and other parameters, so we in here to move the hands and feet on the OK. Source:Value = Properties.getproperty ("password");if (value = null) {Datasource.setpassword (value);} value = Properties.getproperty ("url");if (value = null) {Datasource.seturl (value);} value = Properties.getproperty ("username");if (value = null) {datasource.setusername
=read_uncommittedWriting Custom Dbcputil ClassesOk!C3P0 use steps as consistentCopy jar Package:C3p0-0.9.1.2.jarC3p0-0.9.1.2-jdk1.3.jar (This jar package is not available)C3p0-oracle-thin-extras-0.9.1.2.jar (Oracle database dedicated)Configuration file1.1. XML format1.2.properties file Format (skip)1.3. Set (Combopooleddatasource) Setxxxx property in the class that created the data source2 Creating the C3p0util class provides the connection methodpubl
Label:The steps are as follows:First, install MySQL ODBC driver: Mysql-connector-odbc-5.3.4-win32 Second, open cmd, enter:C:\Windows\SysWOW64\odbcad32.exe (Be sure to enter the full path!) ) Then we're going to configure MySQL ODBC in open ODBC data Source Manager 2.1. 2.2. 2.3. Finally click Test, testing, if the connection is successful, you can click OK to complete the MySQL ODBC configuration. Copyright NOTICE: This article for Bo Master
Tags: database jdbc mysql BDCP javaDbcp:database Connection Pool1, the need of Jar:commons-dbcp.jar Commons-pool.jar2. Copy the DBCP configuration file (dbcpconfig.properties) to the build path3. Create class: DbcputilDbcpconfig.properties:The MySQL setup content is as follows:#连接设置driverClassName =com.mysql.jdbc.driverurl=jdbc:mysql://localhost:3306/day16username=rootpassword=liang# Dbcputil:Package Cn.itcast.util;import Java.io.inputstream;import Java.sql.connection;import java.sql.resultset;i
30,000, the other lost, change Ojdbc6.jar, a commit batch insert 1 million is OK.Try to use a driver that is consistent with the database version, and when there is a bug, replace the newer version of the JDBC driver.If a JDBC jar package you do not know is that version, you can unzip the jar package and then meta-inf\manifest. MF file to find the word "Oracle JDBC Driver version-10.1.0.2.0", you will know the version.Sometimes serious servlet.service () for Servlets [JSP] in the context with p
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.