posts - 189,comments - 115,trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(35)

          我參與的團隊

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          Android

          BLOGS

          Econormic

          Friend-Blog

          Guitar

          J2ME

          JAVA

          Linux

          Linux_driver

          MUSIC

          MY--BLOG

          NET

          NEWS

          ORACLE

          Project

          SOFT

          STUDY

          Sutra<==>Research

          SVN

          Translate

          Vim

          在線翻譯

          娛樂

          文檔教程

          考研

          裝修

          軟件開發

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

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

          偶參照上面寫了一個跟sql連接的頁面,有不少錯誤。 搞得比較郁悶,不過今天剛剛弄好了,要是有需要的就看看偶寫的《jsp連接sql server 2000 完整版》呵呵,或許能讓你少走不少彎路哦,因為我是搞了2天才完全曉得哪里會出問題的哦

          posted on 2006-03-16 11:34 MEYE 閱讀(214) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 陆良县| 曲阜市| 湘乡市| 南雄市| 隆昌县| 大余县| 凌源市| 玉林市| 浦东新区| 涟源市| 浪卡子县| 昌江| 平阳县| 鹤壁市| 雅安市| 文山县| 隆回县| 海丰县| 尉氏县| 博野县| 通州市| 安新县| 咸阳市| 内江市| 天等县| 启东市| 建水县| 临汾市| 白玉县| 柳林县| 西吉县| 铜陵市| 石渠县| 峨山| 安乡县| 万源市| 弥渡县| 观塘区| 长治市| 通化市| 汶上县|