?? dbmanager.java
字號:
package com.bookshop.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author ??????
*
*/
public class DBManager {
public static Connection getConnection() throws SQLException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");//org.gjt.mm.mysql.Driver
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:ora","dbmanager","dbmanager");
//ConnStr="jdbc:mysql://localhost:3306/test?
//user=root&password=123456&useUnicode=true&characterEncoding=gb2312";
return con;
}
public static void clearup(PreparedStatement pstmt) {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException se) {
se.printStackTrace();
}
pstmt = null;
}
}
/**
* Close database resource.
*
* @param conn
* @param pstmt
*/
public static void clearup(Connection conn, PreparedStatement pstmt) {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException se) {
se.printStackTrace();
}
pstmt = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
conn = null;
}
}
/**
* Close databse resource.
*
* @param conn
* @param pstmt
* @param rs
*/
public static void clearup(Connection conn, PreparedStatement pstmt,
ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException se) {
se.printStackTrace();
}
rs = null;
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException se) {
se.printStackTrace();
}
pstmt = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
conn = null;
}
}
/**
* Close databse resource.
* @param pstmt
* @param rs
*/
public static void clearup(PreparedStatement pstmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException se) {
se.printStackTrace();
}
rs = null;
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException se) {
se.printStackTrace();
}
pstmt = null;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -