为了账号安全,请及时绑定邮箱和手机立即绑定

springboot如何配置多个jndi数据源

/ 猿问

springboot如何配置多个jndi数据源

慕运维1137616 2019-03-03 04:00:10

springboot如何配置多个jndi数据源


查看完整描述

2 回答

?
青春有我

代码:

/**
* 获取数据库连接方法
*/
public Connection getConn() throws
Exception {
Connection conn = null;
try {

//connection原始的连接方式可以转换为OracleConnection
Connection con =
this.commonDao.getCurrentConnection();
Connection conWas = null;

if(this.wasConnection){//使用tomcat请把biz-context-finance.xml中的wasConnection的值设置为false
注释掉biz-context-core.xml中的id="websphereForOracleConnection"内容

WebSphereNativeJdbcExtractor websphereForOracleConnection =
(WebSphereNativeJdbcExtractor)SpringUtils.getSpringBean("websphereForOracleConnection");

conWas = websphereForOracleConnection.getNativeConnection(con);
}else{

conWas = con;
}

conWas.setAutoCommit(false);
conn =
conWas.getMetaData().getConnection();
} catch (DaoException e) {

e.printStackTrace();
}
return conn;
}

 


查看完整回答
反对 回复 2019-03-10
?
慕沐林林

一、直连接数据库
1 Java 连接 Oralce

[java] view plaincopy
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection conn= DriverManager.getConnection(url,user,password);

2 Java 连接 MySQL

[java] view plaincopy
Class.forName("org.gjt.mm.mysql.Driver ").newInstance();
String URL = "jdbc:mysql://localhost/test";
Connection conn= DriverManager.getConnection(url,user,password);

3 Java 连接SQLServer

[java] view plaincopy
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String URL =” jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
Connection conn= DriverManager.getConnection(url,user,password);

4 Java 连接DB2

[java] view plaincopy
Class.forName(“com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String URL =”jdbc:db2://localhost:5000/sample";
Connection conn= DriverManager.getConnection(url,user,password);

5 Java 连接 Infomix

[java] view plaincopy
Class.forName("com.informix.jdbc.IfxDriver ").newInstance();
String URL =jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver
Connection conn= DriverManager.getConnection(url,user,password);

6 Java 连接 SyBase

[java] view plaincopy
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);

7 Java连接 PostgreSQL

[java] view plaincopy
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/soft"
Connection conn= DriverManager.getConnection(url,user,password);



查看完整回答
反对 回复 2019-03-10

添加回答

回复

举报

0/150
提交
取消
意见反馈 邀请有奖 帮助中心 APP下载
官方微信