编写实现连接oracle数据库并返回Connection对象的Java工具类

时间:2023-12-24 09:56:31

只需要实现一个功能,所以只写一个方法,为了方便调用,设为静态方法

 package com.jv;

 import java.sql.Connection;
import java.sql.DriverManager; public class Lianjie { //静态方法获取连接对象
public static Connection getLianj() throws Exception
{ Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521:orcl"; Connection conn = DriverManager.getConnection(url, "test","test"); return conn; }
}