各种数据库连接

各种数据库连接:

 

	public void Dbcon() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		//JDBC-ODBC
		String Driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		String URL = "jdbc:odbc:dbsource"; //dbsource为数据源名  

		//Oracle(thin模式): 
		String Driver1 = "oracle.jdbc.driver.OracleDriver"; //连接数据库的方法  
		String URL1 = "jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID  

		//MySQL: 
		String Driver2 = "com.mysql.jdbc.Driver"; //驱动程序    
		String URL2 = "jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名  

		//DB2: 
		String Drive3r = "com.ibm.db2.jdbc.app.DB2.Driver"; //连接具有DB2客户端的Provider实例    
		//String Driver="com.ibm.db2.jdbc.net.DB2.Driver";    //连接不具有DB2客户端的Provider实例    
		String URL3 = "jdbc:db2://localhost:5000/db_name"; //db_name为数据库名  

		//Microsoft SQL Server: 
		String Driver4 = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法    
		String URL4 = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name";

		//Sysbase:
		String Driver5 = "com.sybase.jdbc.SybDriver"; //驱动程序    
		String URL5 = "jdbc:Sysbase://localhost:5007/db_name";

		//PostgreSQL: 
		String Driver6 = "org.postgresql.Driver"; //连接数据库的方法    
		String URL6 = "jdbc:postgresql://localhost/db_name";

		//Informix: 
		String Driver7 = "com.informix.jdbc.IfxDriver";
		String URL7 = "jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver";

		String Username = "username"; //用户名  
		String Password = "password"; //密码  
		Class.forName(Driver).newInstance();
		Connection con = DriverManager.getConnection(URL, Username, Password);
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值