隨筆 - 0, 文章 - 75, 評論 - 0, 引用 - 0
          數(shù)據(jù)加載中……

          用jdbc連接各數(shù)據(jù)庫驅(qū)動


          sql server
          2000下的連接串:
          DRIVER="com.microsoft.jdbc.sqlserver.SQLServerDriver";
          URL="jdbc:microsoft:sqlserver://localhost:1433;databaseName=ssoDemo;user=sa;password=1";

          sql
          server
          2005下的連接串:
          DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
          URL="jdbc:sqlserver://localhost:1433;databaseName=ssoDemo;user=sa;password=1";
          url
          ="jdbc:sqlserver://localhost:1433;instanceName=sqlexpress;database=bbsdb;user=sa;password=123"



          Oracle:
          url:
          jdbc:oracle:oci8:@newer
          driver:
          oracle.jdbc.driver.OracleDriver


          mysql
          url:
          jdbc:mysql://127.0.0.1:3306/mysql
          driver:
          org.gjt.mm.mysql.Driver





          Class.forName("oracle.jdbc.dirver.OracleDriver").newInstance();
          String
          url="jdbc:oracle:thin:@localhost:1521:orcl";
          //這里的orcl為數(shù)據(jù)庫(SID實例名)
          String
          user="system";//用戶名
          String pwd="manager123456";//密碼
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);



          Class.forName("com.sybase.jdbc.SybDriver").newInstance();
          String
          url="jdbc:sybase:Tds:localhost:5007/erp";
          //erp為數(shù)據(jù)庫名
          Properties
          sysProps=System.getProperties();
          sysProps.put("user","sa");//用戶名
          sysProps.put("password","");//密碼
          java.sql.Connection
          conn=DriverManager.getConnection(url,SysProps);





          Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
          String
          url="jdbc:db2://localhost:5000/sample";
          //sample為DB2數(shù)據(jù)庫名
          String
          user="admin";
          String pwd="";//密碼
          java.sql.Connetion
          conn=DriverManager.getConnection(url,user,pwd);





          Class.forName("com.informix.jdbc.IfxDriver").newInstance();
          String
          url="jdbc:informix-sqli://localhost:1533/test:INFORMIXSERVER=infserver";
          user="sa";//用戶名
          password="pwd";//密碼
          //test為數(shù)據(jù)庫名
          //java.sql.Connection
          conn=DriverManager.getConnection(url,user,password);



          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
          String
          url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
          //pubs數(shù)據(jù)庫名
          String
          user="sa";
          String pwd="";
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);




          Class.forName("org.postgresql.Driver").newInstance();
          String
          url="jdbc:postgresql://localhost/netshop";
          //newshop數(shù)據(jù)庫名
          String
          user="root";
          String pwd="123456";
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);



          MySQL:
          String Driver="com.mysql.jdbc.Driver"; //驅(qū)動程序
          String
          URL="jdbc:mysql://localhost:3306/db_name"; //連接的URL,db_name為數(shù)據(jù)庫名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).new Instance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Microsoft SQL Server:
          String
          Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //連接SQL數(shù)據(jù)庫的方法
          String
          URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name";
          //db_name為數(shù)據(jù)庫名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).new Instance();
          //加載數(shù)據(jù)可驅(qū)動
          Connection con=DriverManager.getConnection(URL,UserName,Password);
          //




          Sysbase:
          String Driver="com.sybase.jdbc.SybDriver"; //驅(qū)動程序
          String
          URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name為數(shù)據(jù)可名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Oracle(用thin模式):
          String Driver="oracle.jdbc.driver.OracleDriver";
          //連接數(shù)據(jù)庫的方法
          String URL="jdbc:oracle:this:@loaclhost:1521:orcl";
          //orcl為數(shù)據(jù)庫的SID
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          //加載數(shù)據(jù)庫驅(qū)動
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          PostgreSQL:
          String Driver="org.postgresql.Driver"; //連接數(shù)據(jù)庫的方法
          String
          URL="jdbc:postgresql://localhost/db_name"; //db_name為數(shù)據(jù)可名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          DB2:
          String Driver="com.ibm.db2.jdbc.app.DB2.Driver";
          //連接具有DB2客戶端的Provider實例
          //String Driver="com.ibm.db2.jdbc.net.DB2.Driver";
          //連接不具有DB2客戶端的Provider實例
          String URL="jdbc:db2://localhost:5000/db_name";
          //db_name為數(shù)據(jù)可名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Informix:
          String Driver="com.informix.jdbc.IfxDriver";
          String
          URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver";
          //db_name為數(shù)據(jù)可名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);




          JDBC-ODBC:
          String Driver="sun.jdbc.odbc.JdbcOdbcDriver";
          String
          URL="jdbc:odbc:dbsource"; //dbsource為數(shù)據(jù)源名
          String Username="username";
          //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);

          posted on 2012-04-22 15:31 hantai 閱讀(181) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 双鸭山市| 丰原市| 仲巴县| 巴楚县| 南溪县| 镇赉县| 盐亭县| 昭通市| 尼玛县| 舟曲县| 聂拉木县| 南和县| 陵川县| 大新县| 广宁县| 砚山县| 天门市| 鄂尔多斯市| 南康市| 土默特右旗| 广宗县| 大竹县| 鞍山市| 百色市| 苏州市| 平乡县| 怀化市| 三明市| 清镇市| 夏津县| 扎赉特旗| 彰化县| 华安县| 仲巴县| 定州市| 涞源县| 金山区| 嘉定区| 齐河县| 四川省| 通江县|