greenteazsh
          讓我們攜手一起努力......
          posts - 26,  comments - 18,  trackbacks - 0

          import java.sql.*;

          public class DBTest {
             private Statement stmt;
             private Connection conn;
             ResultSet rs;
             int size;
           
             public void DBTest(){
                stmt=null;
                conn=null;
                rs=null;
                size=0;
             }
           
             public void openConn() throws SQLException{
                try{
                      Class.forName("oracle.jdbc.driver.OracleDriver");
                      String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
                      String user="dectdb";
                      String pwd="dectdb";
                      conn=DriverManager.getConnection(url, user, pwd);
                }catch(ClassNotFoundException classNotFoundException){
                      System.out.println("No Driver!");
                }
             }
           
             public ResultSet executeQuery(String sql){
                  rs=null;
            
                  try{
                      stmt=conn.createStatement();
                      rs=stmt.executeQuery(sql);
                 }catch(SQLException sqlException){
                     System.out.println(sqlException);
                }
            
                return rs;
            }
           
            public int executeUpdate(String sql){
                stmt=null;
                rs=null;
                size=0;
            
                try{
                      stmt=conn.createStatement();
                      size=stmt.executeUpdate(sql);
                }catch(SQLException sqlException){
                      System.out.println(sqlException);
                }
            
                return size;
            }

            public void closeStmt(){
                try{
                stmt.close();
                }catch(SQLException sqlException){
                    System.out.println(sqlException);
                }
            }
           
            public static void main(String[] args){
                DBTest dbTest=new DBTest();
                String sql="select * from dectuser";
                //String sqlUpdate="insert into dectuser(name,sex) values('wang','女')";
            
               try{
                     dbTest.openConn();
                     //int size=dbTest.executeUpdate(sqlUpdate);
                     ResultSet rs=dbTest.executeQuery(sql);
             
                     //System.out.println(size);
                     while(rs.next()){
                              System.out.println(rs.getString("name"));
                     }
             
                    dbTest.closeStmt();
               }catch(SQLException sqlException){
                    System.out.println(sqlException);
              }
            
            
             }
           }

          posted on 2008-04-13 18:42 綠茶 閱讀(265) 評論(1)  編輯  收藏 所屬分類: DataBase

          FeedBack:
          # re: oracle jdbc
          2008-04-13 18:43 | 綠茶
          最近沒有用哦,都有點兒忘了,呵呵,留下  回復(fù)  更多評論
            

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


          網(wǎng)站導(dǎo)航:
           
          在壓力下共生:)
          我們一起成長
          QQ:176739920

          <2008年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 大埔县| 金寨县| 从江县| 桂平市| 什邡市| 道孚县| 南平市| 承德县| 浦城县| 尼玛县| 南召县| 南投市| 宁乡县| 清涧县| 昔阳县| 高青县| 阿瓦提县| 龙口市| 蚌埠市| 大荔县| 沁阳市| 夹江县| 文山县| 西宁市| 阿坝| 新巴尔虎右旗| 河间市| 壤塘县| 江陵县| 洛阳市| 蚌埠市| 台北县| 黎平县| 宜都市| 塘沽区| 左贡县| 迁西县| 安庆市| 郸城县| 梁山县| 澎湖县|