编写实现连接oracle数据库并返回Connection对象的Java工具类
只需要实现一个功能,所以只写一个方法,为了方便调用,设为静态方法
1 package com.jv; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 6 public class Lianjie { 7 8 //静态方法获取连接对象 9 public static Connection getLianj() throws Exception 10 { 11 12 Class.forName("oracle.jdbc.driver.OracleDriver"); 13 14 String url = "jdbc:oracle:thin:@localhost:1521:orcl"; 15 16 Connection conn = DriverManager.getConnection(url, "test","test"); 17 18 return conn; 19 20 } 21 }