如何在tomcat中用jndi配置多个数据库
2015-08-29
展开全部
一、直连接数据库
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);
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);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询