日期:2014-05-20 浏览次数:20876 次
public void saveOARole(Role role) throws SQLException{
Properties pro=new Properties();
String path = Thread.currentThread().getContextClassLoader().getResource("connect.properties").getPath();
try {
pro.load(new FileInputStream(path));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
String ClassName=pro.getProperty("ClassName");
String userName=pro.getProperty("userName");
String userPass=pro.getProperty("userPass");
String url1=pro.getProperty("url1");
try {
Class.forName(ClassName);
try {
con = DriverManager.getConnection(url1, userName, userPass);
} catch (SQLException e) {
e.printStackTrace();
}
try {
stmt = this.con.createStatement();
stmt1 = this.con.createStatement();
stmt2 = this.con.createStatement();
stmt3 = this.con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
rs=stmt.executeQuery("select * from hr_role where name='"+role.getName()+"'");
if(rs.next()==false){
rs1=stmt1.executeQuery("select * from hr_role_type where name='"+role.getType().getName()+"'");
if(rs1.next()==false){
String sql2 = "insert into hr_role_type(name) values ("+"'"+role.getType().getName()+"'"+")";
stmt1.executeUpdate(sql2);
rs2=stmt2.executeQuery("select * from hr_role_type where name='"+role.getType().getName()+"'");
while (rs2.next()) {
String ids=rs2.getString("id");
String sql3 = "insert into hr_role(name,rolecode,type_id) values ("+"'"+role.getName()+"'"+",'"+role.getRolecode()+"'"+",'"+ids+"'"+")";
stmt2.executeUpdate(sql3);
}
}else{
rs3=stmt3.executeQuery("select * from hr_role_type where name='"+role.getType().getName()+"'");
while (rs3.next()) {
String ids1=rs3.getString("id");
String sql1 = "insert into hr_role(name,rolecode,type_id) values ("+"'"+role.getName()+"'"+",'"+role.getRolecode()+"'"+",'"+ids1+"'"+")";
stmt3.executeUpdate(sql1);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
finally{
if (rs3!=null) {
rs3.close();
stmt3.close();
rs3=null;
}
if (rs2!=null) {
rs2.close();
stmt2.close();
rs2=null;
}
if (rs1!=null) {
rs1.close();
stmt1.close();
rs1=null;
}
if (rs!=null) {
rs.close();
stmt.close();
rs=null;
}
con.close();
}
}