package test1;
import java.sql.*;
public class JdbcUtil {
static {
String driverName = "oracle.jdbc.driver.OracleDriver";
try {
Class.forName(driverName);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection con = null;
String url = "jdbc:oracle:thin:@61.132.0.46:1521:orcl";
String user = "credit_lyg";
String pwd = "1";
try {
con = DriverManager.getConnection(url, user, pwd);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(con);
return con;
}
public static void close(ResultSet rs, Statement stmt, Connection con) {
try {
if (rs != null)
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
if (stmt != null)
stmt.close();
} catch (Exception ex) {
ex.printStackTrace();
}
try {
if (con != null)
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void close(Object o) {
try {
if (o instanceof ResultSet) {
((ResultSet) o).close();
} else if (o instanceof Statement) {
((Statement) o).close();
} else if (o instanceof Connection) {
((Connection) o).close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
JDBC连接oracle
最新推荐文章于 2023-01-13 15:08:13 发布