中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 数据库开发 > Mysql
如何用 jdbc 连接各种数据库方式列表
作者:gaozj  时间:2006-10-10 14:28 出处:ccidnet.com 责编:月夜寒箫
              摘要:如何用 jdbc 连接各种数据库方式列表

jdbc连接各种数据库方式列表

下面罗列了各种数据库使用JDBC连接的方式,可以作为一个手册使用。












 

  1、Oracle8/8i/9i数据库(thin模式)

 

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
            String user="test";
            String password="test";
            Connection conn= DriverManager.getConnection(url,user,password);

 

 

 

  2、DB2数据库

 

Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
            String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名
            String user="admin";
            String password="";
            Connection conn= DriverManager.getConnection(url,user,password);

 

 

 

  3、Sql Server7.0/2000数据库

 

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
            //mydb为数据库
            String user="sa";
            String password="";
            Connection conn= DriverManager.getConnection(url,user,password);

 

 

 

  4、Sybase数据库

 

Class.forName("com.sybase.jdbc.SybDriver").newInstance();
            String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名
            Properties sysProps = System.getProperties();
            SysProps.put("user","userid");
            SysProps.put("password","user_password");
            Connection conn= DriverManager.getConnection(url, SysProps);

 

 

 

  5、Informix数据库

 

 

Class.forName("com.informix.jdbc.IfxDriver").newInstance();
            String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
            user=testuser;password=testpassword"; //myDB为数据库名
            Connection conn= DriverManager.getConnection(url);

 

 

  6、MySQL数据库

 

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
            //或者Class.forName("com.mysql.jdbc.Driver");
            String url ="jdbc:mysql://localhost/myDB?
            user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
            //myDB为数据库名
            Connection conn= DriverManager.getConnection(url);

 

 

 

  7、PostgreSQL数据库

 

Class.forName("org.postgresql.Driver").newInstance();
            String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名
            String user="myuser";
            String password="mypassword";
            Connection conn= DriverManager.getConnection(url,user,password);

 

 

 

  8、access数据库直连用ODBC的

 

 

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
            String url="jdbc:odbc:Driver={MicroSoft Access Driver
            (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
            Connection conn = DriverManager.getConnection(url,"","");
            Statement stmtNew=conn.createStatement() ;
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有