weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
          數(shù)據(jù)加載中……

          JDBC連接各種數(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&useUnicod
          e=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);

          from: http://www.jspcn.net/htmlnews/11049388537651402.html

          posted on 2006-05-06 23:29 weidagang2046 閱讀(131) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 驻马店市| 建德市| 保亭| 象州县| 荥经县| 洞头县| 武冈市| 天气| 清流县| 溆浦县| 澄江县| 丰宁| 吉木萨尔县| 旺苍县| 隆回县| 临泽县| 焉耆| 常州市| 黄骅市| 阿拉善右旗| 毕节市| 平武县| 天长市| 二手房| 嵩明县| 定南县| 巴林左旗| 库尔勒市| 神木县| 永顺县| 清苑县| 安龙县| 广灵县| 宜城市| 肃宁县| 宁阳县| 绵阳市| 宜君县| 定州市| 涞源县| 曲周县|