Java on Line

          和java的日子!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            8 隨筆 :: 0 文章 :: 28 評(píng)論 :: 0 Trackbacks
          1、Oracle8/8i/9i數(shù)據(jù)庫(kù)(thin模式)
              Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
              String url
          ="jdbc:oracle:thin:@localhost:1521:orcl";
              
          //orcl為數(shù)據(jù)庫(kù)的SID
              String user="test";
              String passWord
          ="test";
              Connection conn
          = DriverManager.getConnection(url,user,password);

          //小例子
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                      String url
          ="jdbc:oracle:thin:@localhost:1521:orcl";
                      conn
          = DriverManager.getConnection(url,"commerce","password");
                      
          //查詢
                      rs = stm.executeQuery("select id,name from T1");
                      
          while(rs.next()){
                          System.out.println(
          "id:"+rs.getString(1));
                          System.out.println(
          "name:"+rs.getString(2));
                      }

                      
                      stm.execute(
          "inset into T1(id,name) values(1,"dd")");           //
                      stm.executeUpdate("delete from T1 where id = 2");               //
                      stm.executeUpdate("update T1 set name = 'bb' where id = 3");//

          //PreparedStatement用法
          PreparedStatement pstm = null;
          pstm.conn.prepareStatement(
          "insert into T1(id,name) values(?,?)");
          pstm.setInt(
          1,4);//1表示第一個(gè)?號(hào),插入值為4
          pstm.setString(2,"小陳");//2表示第二個(gè)?號(hào),插入值為"小陳"
          pstm.executeUpdate();//真正插入數(shù)據(jù)庫(kù)

          2、DB2數(shù)據(jù)庫(kù)
              Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
              String url
          ="jdbc:db2://localhost:5000/sample";
              
          //sample為你的數(shù)據(jù)庫(kù)名
              String user="admin";
              String password
          ="";
              Connection conn
          = DriverManager.getConnection(url,user,password);  

          3、Sql Server7.0/2000數(shù)據(jù)庫(kù)
              Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
              String url
          ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
              
          //mydb為數(shù)據(jù)庫(kù)
              String user="sa";
              String password
          ="";
              Connection conn
          = DriverManager.getConnection(url,user,password); 

          4、Sybase數(shù)據(jù)庫(kù)
              Class.forName("com.sybase.jdbc.SybDriver").newInstance();
              String url 
          =" jdbc:sybase:Tds:localhost:5007/myDB";
              
          //myDB為你的數(shù)據(jù)庫(kù)名
              Properties sysProps = System.getProperties();
              SysProps.put(
          "user","userid");
              SysProps.put(
          "password","user_password");
              Connection conn
          = DriverManager.getConnection(url, SysProps);  

           5、Informix數(shù)據(jù)庫(kù)
              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ù)庫(kù)名
              Connection conn= DriverManager.getConnection(url); 

          6、mysql數(shù)據(jù)庫(kù)
              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ù)庫(kù)名
              Connection conn= DriverManager.getConnection(url); 

          7、PostgreSQL數(shù)據(jù)庫(kù)
              Class.forName("org.postgresql.Driver").newInstance();
              String url 
          ="jdbc:postgresql://localhost/myDB"
              
          //myDB為數(shù)據(jù)庫(kù)名
              String user="myuser";
              String password
          ="mypassword";
              Connection conn
          = DriverManager.getConnection(url,user,password);
          posted on 2008-04-16 16:06 陳東 閱讀(375) 評(píng)論(0)  編輯  收藏 所屬分類: Java基礎(chǔ)
          主站蜘蛛池模板: 庄河市| 仪征市| 内黄县| 贞丰县| 武夷山市| 建平县| 沅陵县| 水城县| 九江县| 建昌县| 唐河县| 上饶市| 南康市| 新泰市| 嘉善县| 饶河县| 灵寿县| 开远市| 剑川县| 平远县| 许昌市| 台安县| 和平县| 乌拉特前旗| 惠东县| 历史| 萨嘎县| 涟水县| 边坝县| 陵水| 兰考县| 普定县| 新竹市| 尚义县| 高尔夫| 定襄县| 扬中市| 阿尔山市| 平江县| 东源县| 高唐县|