1.下載OracleJDBC驅動。(Oracle11.2.0.2)html
http://www.oracle.com/technetwork/cn/database/enterprise-edition/jdbc-112010-094555-zhs.htmloracle
或者在ORACLE_HOME/jdbc/lib下獲取JDBC驅動ide
2.導入OracleJDBC驅動ui
Eclipse: Build Path->Libraries->Add External JARs…->D:\Java\jdk1.6.0_10\lib\ojdbc6.jarurl
3. 創建Oracle鏈接:spa
//@聲明變量:htm
String dburl = "jdbc:oracle:thin:@10.224.xx.xx:1525:urd";blog
Stringuser = "dbcs";ip
Stringpassword = "pass";get
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();
}
}