2016-05-17 07:12题主

如何配置多个数据库?

我的应用需要连接多个数据库里的表,请问怎么配置。
2016-05-17 08:04#1

Tomcat/conf下编辑context.xml

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE Context>
 <Context reloadable="true" crossContext="true">
     <WatchedResource>WEB-INF/web.xml</WatchedResource>
     <Resource
         name="jdbc/wb_oracleserver"
         auth="Container" type="javax.sql.DataSource"
         driverClassName="oracle.jdbc.driver.OracleDriver"
         url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
         username="wb" password="ok"
         maxActive="100" maxIdle="30" maxWait="10000" />
<!--  
basecode
-->
     <Resource
         name="jdbc/basecode_db"
         auth="Container" type="javax.sql.DataSource"
         driverClassName="oracle.jdbc.driver.OracleDriver"
         url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
         username="basecode" password="ok"
         maxActive="100" maxIdle="30" maxWait="10000" />

</Context>

然后添加JNDI

2016-05-18 13:03#2
配置多个数据库,需要先配置jndi,
然后在数据库访问组件里指定需要访问数据库的jndi即可,常用数据库的jndi配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Context>
<Context reloadable="true" crossContext="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/wb_mysql" auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/webbuilder?autoReconnect=true&amp;allowMultiQueries=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;mysqlEncoding=utf8"
username="root" password="webbuilder" maxActive="20" maxIdle="10"
maxWait="-1" />
<Resource name="jdbc/wb_sqlserver" auth="Container" type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=wb"
username="sa" password="webbuilder" maxActive="20" maxIdle="10"
maxWait="-1" />
<Resource name="jdbc/wb_oracle" auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:wb"
username="webbuilder" password="webbuilder" maxActive="20" maxIdle="10"
maxWait="-1" />
</Context>
2016-05-19 13:36#3
有没有人搞过hadoop,怎么配置?

返回开发者社区