package com.chinasoft.corpinfosys.common;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* JdbcUtil类 管理数据库操作
* 管理Connection连接于关闭 功能: 创建Connection 关闭Connection、Statement、ResultSet。
* 已接收异常
*
*
*/
public class JdbcUtil
{
// 创建数据库操作连接
public static Connection getConnection()
{
Connection conn = null;
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String username = "cims";
String password = "cims";
try
{
//加载驱动
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//获得连接
conn = DriverManager.getConnection(url, username, password);
}
catch (SQLException e)
{
// 没获得conn
e.printStackTrace();
}
return conn;
}
//关闭结果集
public static void closeResultSet(ResultSet rs)
{
try
{
rs.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
//关闭statement
public static void closeStatement(Statement sm)
{
if (sm != null)
{
try
{
sm.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
//关闭连接
public static void closeConnection(Connection conn)
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
oracle 数据库连接工具类
最新推荐文章于 2024-08-14 11:43:40 发布