数据库操作:java连接ORACLE实例代码演示

package com.qiaole.conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Oracle {
 public static void main(String[] args) {
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
   String url = "jdbc:oracle:thin:@localhost:1521:xe";
   Connection conn = DriverManager.getConnection(url, "sa", "abc");
   String sql = "select * from \"T_Person\"";
   PreparedStatement psStatement = conn.prepareStatement(sql);
   ResultSet rSet = psStatement.executeQuery();
   System.out.println("\tOracle查询数据");
   while (rSet.next()) {
    System.out.println(rSet.getString(1) + "\t" + rSet.getInt(2)
      + "\t" + rSet.getString(3));
   }

  } catch (InstantiationException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  } catch (SQLException e) {
   e.printStackTrace();
  }
 }
}

 

需要添加的包:

posted on 2010-07-09 09:19  快乐每一天Joe  阅读(827)  评论(0编辑  收藏  举报

导航