Java JDBC连接Oracle11.2.0.2(Eclipse)

1.下载OracleJDBC驱动。(Oracle11.2.0.2

http://www.oracle.com/technetwork/cn/database/enterprise-edition/jdbc-112010-094555-zhs.html

或者在ORACLE_HOME/jdbc/lib下获取JDBC驱动

2.导入OracleJDBC驱动

Eclipse: Build Path->Libraries->Add External JARs…->D:\Java\jdk1.6.0_10\lib\ojdbc6.jar

3. 建立Oracle连接:

//@声明变量:

String dburl = "jdbc:oracle:thin:@10.224.xx.xx:1525:urd";

      Stringuser = "dbcs";

      Stringpassword = "pass";

      Connectioncon = null;

      Statementst=null;

      ResultSet rs = null;


//@建立连接:

publicvoid conOracle() {

try {

                    System.out.println("DBconnection");

                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

long s=System.currentTimeMillis();

                    System.out.println("OracleConnect start.");

con=DriverManager.getConnection(dburl,user,password);

long e=System.currentTimeMillis();

                    System.out.println("TimeEclipsed: "+(e-s));

st=con.createStatement();

                    System.out.println("ConnectOracle DB Successfully.");


             }catch (Exception e) {

                    System.out.println("Not foundOracle DB.");

                    e.printStackTrace();

             }

      }


你可能感兴趣的:(java,oracle,jdbc)