Connection conn = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
//数据库IP
String ip = "oracle数据库IP地址或者是localhost";
// 数据库名称
String dataBaseName = "数据库名称";
// 用户名
String userName = "你的用户名";
// 密码
String password = "你的密码";
// 连接
conn = DriverManager.getConnection("jdbc:oracle:thin:@//" + ip + ":1521/dataBaseName", userName, password);
if(conn != null ){
conn.setAutoCommit(false);
// 执行查询语句
ResultSet resultSet = conn.prepareStatement("sql语句").executeQuery();
// 执行删除更新或者插入语句
conn.prepareStatement("sql语句").executeUpdate();
}else{
System.out.println("操作失败!");
}
}catch (Exception e) {
System.out.println(e.getMessage());
try {
conn.rollback();
} catch (Exception e1) {
System.out.println("事务回滚失败!");
e1.printStackTrace();
}
} finally{
try {
conn.close();
} catch (Exception e) {
}
}
标签:语句,java,String,代码,System,println,oracle,conn
From: https://www.cnblogs.com/Fantasyfzg/p/16784477.html