Java操作Oracle
public class DBCon { // 数据库驱动对象public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
// 数据库连接地址(数据库名)
public static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
// 登陆名
public static final String USER = "scott";
// 登陆密码
public static final String PWD = "123456";
// 创建数据库连接对象
private Connection con = null;
// 创建数据库预编译对象
private PreparedStatement ps = null;
// 创建结果集
private ResultSet rs = null;
// 创建数据源对象
public static DataSource source = null;
public Connection getCon() {
try{
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, USER, PWD);
System.out.println("数据库连接成功!");
} catch (Exception e) {
System.err.println("数据库连接失败!");
e.printStackTrace();
}
return con;
}
public void closeAll() {
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (ps != null)
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (con != null)
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public int update(String sql,String... pras){
int resu=0;
con=getCon();
try {
ps=con.prepareStatement(sql);
for(int i=0;i
页:
[1]