码迷,mamicode.com
首页 > 数据库 > 详细

JDBCUtil

时间:2018-12-03 13:56:11      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:connect   返回   edr   pre   用户   vat   return   prepare   对象   

package com.links.dao.impl;

import java.sql.*;

public class JDBCUtil {
// 数据库驱动类??
private static final String Driver = "oracle.jdbc.driver.OracleDriver";
// 数据库地??
private static final String url = "jdbc:oracle:thin:@192.168.99.201:1521:TEST";
// 用户
private static final String user = "test02";
// 密码
private static final String pwd = "test02";

/**
* 创建数据库链接conn对象
* @return
*/
public static Connection getConnection() {
Connection conn = null;
try {
// 虚拟机装载驱动类
Class.forName(Driver);
// 连接数据??
conn = DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

/**
*
* @param conn 数据库的链接对象
* @param stmt 无参数操作数据库的对??
* @param psmt 有参数操作数据库的对??
* @param rs 返回结果??
*/
public static void close(Connection conn, Statement stmt, PreparedStatement psmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (psmt != null) {
psmt.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

JDBCUtil

标签:connect   返回   edr   pre   用户   vat   return   prepare   对象   

原文地址:https://www.cnblogs.com/xiaopangyu/p/9330154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!