連接各種數據庫寫法

          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 2007-07-25 21:00 hugh 閱讀(641) 評論(1)  編輯  收藏 所屬分類: JAVA

          評論

          # re: 連接各種數據庫寫法 2014-10-17 10:36 ycyyww

          Class.forName("org.postgresql.Driver").newInstance();
          呵呵  回復  更多評論   

          <2014年10月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          公告

          小弟打算把硬盤里的所有資料整理到博客里,但是其中收藏了不少網上的文章(個人也記不住作者),請作者見諒!請知道作者的朋友(或作者本人)看到了請告訴小弟,小弟好把作者加上!

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 广平县| 天柱县| 合江县| 大庆市| 无极县| 大邑县| 山东省| 合作市| 塔河县| 霞浦县| 荆门市| 十堰市| 奉节县| 葵青区| 驻马店市| 彭州市| 海晏县| 安龙县| 桦南县| 游戏| 库车县| 察隅县| 洛宁县| 建德市| 白河县| 徐州市| 神木县| 平阳县| 五华县| 玛曲县| 翁牛特旗| 衡东县| 正定县| 德清县| 岑巩县| 金昌市| 斗六市| 喀什市| 八宿县| 楚雄市| 环江|