您的位置:首页 > 数据库 > Oracle

JDBC连接oracle

2013-01-21 22:11 225 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: