Oracle数据库连接
1 package com.schiller; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 6 public class Test { 7 private static String driver = "oracle.jdbc.driver.OracleDriver"; 8 private static String url = "jdbc:oracle:thin:@139.138.137.2:1521:ORa2"; //ORa2是数据库实例的SID,在tnsnames.ora中查找 9 private static String name = "cxyh"; 10 private static String password = "cxyh"; 11 private static Connection conn = null; 12 13 public static void main(String[] args) throws Exception { 14 Class.forName(driver); 15 conn = DriverManager.getConnection(url,name,password); 16 System.out.println(conn); 17 conn.close(); 18 } 19 }
备注:ojdbc14.jar支持jdk1.4,ojdbc6.jar支持jdk6