神秘的 J2ee 殿堂

          ·古之學者必有師·做學者亦要做師者·FIGHTING·

          連接各種數(shù)據(jù)庫方式速查表

          連接各種數(shù)據(jù)庫方式速查表

          下面羅列了各種數(shù)據(jù)庫使用JDBC連接的方式,可以作為一個手冊使用。

          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); 
          8、access數(shù)據(jù)庫直連用ODBC的

          Class.forName(
          "sun.jdbc.odbc.JdbcOdbcDriver") ;
          String url
          ="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
          Connection conn 
          = DriverManager.getConnection(url,"","");
          Statement stmtNew
          =conn.createStatement() ;
          《轉(zhuǎn)》

          posted on 2008-04-25 16:07 月芽兒 閱讀(243) 評論(0)  編輯  收藏 所屬分類: J2EE學習摘錄

          導航

          統(tǒng)計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 安吉县| 彭山县| 绥棱县| 高陵县| 苍山县| 柘荣县| 宝鸡市| 和林格尔县| 威远县| 嘉黎县| 镇坪县| 阿拉尔市| 从化市| 正安县| 习水县| 宜城市| 上饶市| 北流市| 桐庐县| 固安县| 平昌县| 临颍县| 昌平区| 德江县| 朝阳市| 伽师县| 咸宁市| 昆山市| 高阳县| 青州市| 刚察县| 通州市| 江永县| 中卫市| 桦川县| 武鸣县| 江孜县| 永仁县| 尼玛县| 眉山市| 聂拉木县|