隨筆 - 0, 文章 - 75, 評(píng)論 - 0, 引用 - 0
          數(shù)據(jù)加載中……

          用jdbc連接各數(shù)據(jù)庫(kù)驅(qū)動(dòng)


          sql server
          2000下的連接串:
          DRIVER="com.microsoft.jdbc.sqlserver.SQLServerDriver";
          URL="jdbc:microsoft:sqlserver://localhost:1433;databaseName=ssoDemo;user=sa;password=1";

          sql
          server
          2005下的連接串:
          DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
          URL="jdbc:sqlserver://localhost:1433;databaseName=ssoDemo;user=sa;password=1";
          url
          ="jdbc:sqlserver://localhost:1433;instanceName=sqlexpress;database=bbsdb;user=sa;password=123"



          Oracle:
          url:
          jdbc:oracle:oci8:@newer
          driver:
          oracle.jdbc.driver.OracleDriver


          mysql
          url:
          jdbc:mysql://127.0.0.1:3306/mysql
          driver:
          org.gjt.mm.mysql.Driver





          Class.forName("oracle.jdbc.dirver.OracleDriver").newInstance();
          String
          url="jdbc:oracle:thin:@localhost:1521:orcl";
          //這里的orcl為數(shù)據(jù)庫(kù)(SID實(shí)例名)
          String
          user="system";//用戶名
          String pwd="manager123456";//密碼
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);



          Class.forName("com.sybase.jdbc.SybDriver").newInstance();
          String
          url="jdbc:sybase:Tds:localhost:5007/erp";
          //erp為數(shù)據(jù)庫(kù)名
          Properties
          sysProps=System.getProperties();
          sysProps.put("user","sa");//用戶名
          sysProps.put("password","");//密碼
          java.sql.Connection
          conn=DriverManager.getConnection(url,SysProps);





          Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
          String
          url="jdbc:db2://localhost:5000/sample";
          //sample為DB2數(shù)據(jù)庫(kù)名
          String
          user="admin";
          String pwd="";//密碼
          java.sql.Connetion
          conn=DriverManager.getConnection(url,user,pwd);





          Class.forName("com.informix.jdbc.IfxDriver").newInstance();
          String
          url="jdbc:informix-sqli://localhost:1533/test:INFORMIXSERVER=infserver";
          user="sa";//用戶名
          password="pwd";//密碼
          //test為數(shù)據(jù)庫(kù)名
          //java.sql.Connection
          conn=DriverManager.getConnection(url,user,password);



          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
          String
          url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
          //pubs數(shù)據(jù)庫(kù)名
          String
          user="sa";
          String pwd="";
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);




          Class.forName("org.postgresql.Driver").newInstance();
          String
          url="jdbc:postgresql://localhost/netshop";
          //newshop數(shù)據(jù)庫(kù)名
          String
          user="root";
          String pwd="123456";
          java.sql.Connection
          conn=DriverManager.getConnection(url,user,pwd);



          MySQL:
          String Driver="com.mysql.jdbc.Driver"; //驅(qū)動(dòng)程序
          String
          URL="jdbc:mysql://localhost:3306/db_name"; //連接的URL,db_name為數(shù)據(jù)庫(kù)名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).new Instance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Microsoft SQL Server:
          String
          Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //連接SQL數(shù)據(jù)庫(kù)的方法
          String
          URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name";
          //db_name為數(shù)據(jù)庫(kù)名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).new Instance();
          //加載數(shù)據(jù)可驅(qū)動(dòng)
          Connection con=DriverManager.getConnection(URL,UserName,Password);
          //




          Sysbase:
          String Driver="com.sybase.jdbc.SybDriver"; //驅(qū)動(dòng)程序
          String
          URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name為數(shù)據(jù)可名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Oracle(用thin模式):
          String Driver="oracle.jdbc.driver.OracleDriver";
          //連接數(shù)據(jù)庫(kù)的方法
          String URL="jdbc:oracle:this:@loaclhost:1521:orcl";
          //orcl為數(shù)據(jù)庫(kù)的SID
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          //加載數(shù)據(jù)庫(kù)驅(qū)動(dòng)
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          PostgreSQL:
          String Driver="org.postgresql.Driver"; //連接數(shù)據(jù)庫(kù)的方法
          String
          URL="jdbc:postgresql://localhost/db_name"; //db_name為數(shù)據(jù)可名
          String
          Username="username"; //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          DB2:
          String Driver="com.ibm.db2.jdbc.app.DB2.Driver";
          //連接具有DB2客戶端的Provider實(shí)例
          //String Driver="com.ibm.db2.jdbc.net.DB2.Driver";
          //連接不具有DB2客戶端的Provider實(shí)例
          String URL="jdbc:db2://localhost:5000/db_name";
          //db_name為數(shù)據(jù)可名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);



          Informix:
          String Driver="com.informix.jdbc.IfxDriver";
          String
          URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver";
          //db_name為數(shù)據(jù)可名
          String Username="username"; //用戶名
          String
          Password="password"; //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);




          JDBC-ODBC:
          String Driver="sun.jdbc.odbc.JdbcOdbcDriver";
          String
          URL="jdbc:odbc:dbsource"; //dbsource為數(shù)據(jù)源名
          String Username="username";
          //用戶名
          String Password="password";
          //密碼
          Class.forName(Driver).newInstance();
          Connection
          con=DriverManager.getConnection(URL,Username,Password);

          posted on 2012-04-22 15:31 hantai 閱讀(178) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 平度市| 石屏县| 南木林县| 湟中县| 陆河县| 广德县| 大新县| 泰来县| 清丰县| 广元市| 库尔勒市| 读书| 二手房| 根河市| 河津市| 绥中县| 普洱| 衡水市| 阿图什市| 简阳市| 龙游县| 长阳| 德阳市| 全南县| 车致| 政和县| 宜君县| 绍兴县| 科尔| 安远县| 盐亭县| 临漳县| 靖安县| 恩施市| 云南省| 富裕县| 辰溪县| 察隅县| 岐山县| 西和县| 舟曲县|