日期:2014-05-16 浏览次数:20526 次
?
package edu.njcit.db; import java.sql.Connection; import java.sql.DriverManager; /** * JAVA连接ORACLE数据库 * @author Administrator * */ public class ConnOracle { static final String DRIVER="oracle.jdbc.driver.OracleDriver"; static final String URL="jdbc:oracle:thin@127.0.0.1:1521:mydb"; public static void main(String[] args) { try { //第一步:加载驱动器 Class.forName(DRIVER).newInstance(); //第二步:调用DriverManager.getConnection静态方法得到数据库连接 Connection conn = DriverManager.getConnection(URL, "sa", "sa"); } catch(Exception e) { System.out.println("连接到oracle数据库失败."); e.printStackTrace(); } } }?
?
?