java 連接各種數(shù)據(jù)庫(kù)代碼

          此文中的代碼主要列出連接數(shù)據(jù)庫(kù)的關(guān)鍵代碼,其他訪問(wèn)數(shù)據(jù)庫(kù)代碼省略

          1、Oracle8/8i/9i數(shù)據(jù)庫(kù)(thin模式)
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
          String url="jdbc:oracle:thin:@localhost:1521:orcl";
          //orcl為數(shù)據(jù)庫(kù)的SID
          String user="test";
          String password="test";
          Connection conn= DriverManager.getConnection(url,user,password);

          2、DB2數(shù)據(jù)庫(kù)
          Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
          String url="jdbc:db2://localhost:5000/sample";
          //sample為你的數(shù)據(jù)庫(kù)名
          String user="admin";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);

          3、Sql Server7.0/2000數(shù)據(jù)庫(kù)
          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
          String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
          //mydb為數(shù)據(jù)庫(kù)
          String user="sa";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);

          4、Sybase數(shù)據(jù)庫(kù)
          Class.forName("com.sybase.jdbc.SybDriver").newInstance();
          String url =" jdbc:sybase:Tds:localhost:5007/myDB";
          //myDB為你的數(shù)據(jù)庫(kù)名
          Properties sysProps = System.getProperties();
          SysProps.put("user","userid");
          SysProps.put("password","user_password");
          Connection conn= DriverManager.getConnection(url, SysProps);

          5、Informix數(shù)據(jù)庫(kù)
          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為數(shù)據(jù)庫(kù)名
          Connection conn= DriverManager.getConnection(url);

          6、MySQL數(shù)據(jù)庫(kù)
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
          //myDB為數(shù)據(jù)庫(kù)名
          Connection conn= DriverManager.getConnection(url);

          7、PostgreSQL數(shù)據(jù)庫(kù)
          Class.forName("org.postgresql.Driver").newInstance();
          String url ="

          posted on 2008-06-30 10:32 海內(nèi)知己 閱讀(128) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2008年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 府谷县| 舟山市| 乡城县| 延川县| 金塔县| 三亚市| 沅江市| 班玛县| 高青县| 潜江市| 西乌珠穆沁旗| 桐城市| 长沙县| 广安市| 汨罗市| 和硕县| 子长县| 尖扎县| 大新县| 韶山市| 永福县| 兴国县| 庄河市| 神木县| 闽清县| 旬邑县| 自贡市| 东乌珠穆沁旗| 卓资县| 会宁县| 梁平县| 新巴尔虎左旗| 建水县| 高安市| 富源县| 天水市| 寿阳县| 长兴县| 焦作市| 嘉禾县| 南乐县|