import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Hashtable;
public class Test {
public void queryFromOracle() throws Exception {
Connection conn = null;
ResultSet rs = null;
String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String username = "test";
String password = "test";
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
String sql1 = "select t1.usercode,t2.usertype from app_userchangerecord t1 left join base_user t2 on t1.usercode = t2.code";
String sql2 = "update app_userchangerecord t set t.usertype = ? where usercode = ?";
ps1 = conn.prepareStatement(sql1);
ps2 = conn.prepareStatement(sql2);
String code;
String usertype;
rs = ps1.executeQuery();
while (rs.next()) {
code = rs.getString(1);
usertype = rs.getString(2);
ps2.setString(1, usertype);
ps2.setString(2, code);
ps2.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ps1.close();
ps2.close();
rs.close();
}
}
}
jdbc连接oracle实例
最新推荐文章于 2022-04-20 09:01:17 发布