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 绿茶 阅读(246) 评论(1)  编辑  收藏 所属分类: DataBase

FeedBack:
# re: oracle jdbc
2008-04-13 18:43 | 绿茶
最近没有用哦,都有点儿忘了,呵呵,留下  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
在压力下共生:)
我们一起成长
QQ:176739920

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

常用链接

留言簿(1)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜