JDBC连接Oracle数据库类:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* JDBC连接Oracle
*
* @author
*
*/
public class JDBCConnUtils {
private static final String DRIVER = "oracle.jdbc.OracleDriver";
private static final String URL = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
private static final String USERNAME = "xue";
private static final String PASSWORD = "admin";
/**
* 获得连接
*
* @return Connection
*/
public static Connection getConn() {
Connection conn = null;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
/**
* 关闭资源
*
* @param rs
* @param st
* @param conn
*/
public static void closeALl(ResultSet rs, PreparedStatement st,
Connection conn) {
if (rs != null) {
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if (st != null) {
try {
st.close();
st = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
conn = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}