世界因你而精彩___vv

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

           

          Java連接各種數據庫的實例

          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();

          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);



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

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


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類(4)

          隨筆檔案(7)

          文章分類(10)

          文章檔案(11)

          相冊

          最新隨筆

          搜索

          最新評論

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

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 偃师市| 高雄县| 广东省| 两当县| 信宜市| 长子县| 色达县| 铜鼓县| 原平市| 陵水| 和政县| 永胜县| 中牟县| 图木舒克市| 德惠市| 彭阳县| 营山县| 垣曲县| 呈贡县| 辽宁省| 文山县| 临洮县| 镇赉县| 大庆市| 郧西县| 江达县| 桑日县| 巧家县| 加查县| 丹寨县| 祁连县| 乡城县| 武定县| 南溪县| 化州市| 林甸县| 宁夏| 瓦房店市| 宣武区| 贵州省| 金门县|