世界因你而精彩___vv

          要么忙著生存,要么趕著去死!人總是要做點什么的!

           

          Java連接各種數(shù)據(jù)庫的實例

          1、Oracle8/8i/9i數(shù)據(jù)庫(thin模式)

                      

          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

          String url="jdbc:oracle:thin:@localhost:1521:orcl";

          //orcl為數(shù)據(jù)庫的SID

          String user="test";

          String password="test";

          Connection conn= DriverManager.getConnection(url,user,password);



          2、DB2數(shù)據(jù)庫

                      

          Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();

          String url="jdbc:db2://localhost:5000/sample";

          //sample為你的數(shù)據(jù)庫名

          String user="admin";

          String password="";

          Connection conn= DriverManager.getConnection(url,user,password);



          3、Sql Server7.0/2000數(shù)據(jù)庫

                      

          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

          String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";

          //mydb為數(shù)據(jù)庫

          String user="sa";

          String password="";

          Connection conn= DriverManager.getConnection(url,user,password);



          4、Sybase數(shù)據(jù)庫

                      

          Class.forName("com.sybase.jdbc.SybDriver").newInstance();

          String url =" jdbc:sybase:Tds:localhost:5007/myDB";

          //myDB為你的數(shù)據(jù)庫名

          Properties sysProps = System.getProperties();

          SysProps.put("user","userid");

          SysProps.put("password","user_password");

          Connection conn= DriverManager.getConnection(url, SysProps);



          5、Informix數(shù)據(jù)庫

                      

          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ù)庫名

          Connection conn= DriverManager.getConnection(url);



          6、MySQL數(shù)據(jù)庫

                      

          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ù)庫名

          Connection conn= DriverManager.getConnection(url);



          7、PostgreSQL數(shù)據(jù)庫

                      

          Class.forName("org.postgresql.Driver").newInstance();

          String url ="jdbc:postgresql://localhost/myDB"

          //myDB為數(shù)據(jù)庫名

          String user="myuser";

          String password="mypassword";

          Connection conn= DriverManager.getConnection(url,user,password);



          要么忙著生存,要么趕著去死!人總是要做點什么的!

          posted on 2008-01-03 17:29 vv 閱讀(249) 評論(0)  編輯  收藏 所屬分類: DB


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


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(2)

          隨筆分類(4)

          隨筆檔案(7)

          文章分類(10)

          文章檔案(11)

          相冊

          最新隨筆

          搜索

          最新評論

          • 1.?re: 過濾頁面中沒有用到的圖片[未登錄]
          • 在非洲,瞪羚每天早上醒來時,他知道自己必須跑的比最快的獅子還快,否則就會被吃掉.獅子每天早上醒來時,他知道自己必須追上跑得最慢的瞪羚,否則就會被餓死.不管你是獅子還是瞪羚,當(dāng)太陽升起時,你最好開始奔跑
          • --Eleven

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 荥阳市| 张家港市| 罗田县| 乃东县| 开化县| 门源| 昆山市| 大连市| 新邵县| 横峰县| 富阳市| 舟曲县| 灵武市| 德化县| 中超| 阳江市| 铁岭县| 理塘县| 怀柔区| 苍山县| 延安市| 涞水县| 西华县| 桃园县| 保德县| 古田县| 华容县| 阳朔县| 广南县| 清水县| 天祝| 青海省| 大理市| 旬邑县| 宁明县| 安仁县| 阿城市| 绍兴市| 甘孜| 盐边县| 福鼎市|