1: …… 2: public void f() { 3: try { 4: // caltalog 값으로 c1과 c2를 사용할 경우 5: InitialContext ctx = new InitialContext(); 6: DataSource datasource = (DataSource) ctx.lookup("jdbc:ocl:orcl"); 7: Connection con = datasource.getConnection(); 8: 9: Properties props = new Properties(); 10: String fileName= "file.properties"; 11: String catalog; 12: 13: FileInputStream in = new FileInputStream(fileName); 14: if (in != null && in.available() > 0) { 15: props.load(in); 16: 17: if (props == null || props.isEmpty()) catalog = "c1"; 18: else 19: catalog = props.getProperty("catalog"); 20: } else 21: catalog = "c1"; 22: 23: // 외부 유입 변수(catalog)에 대해서 값을 반드시 체크하고 걸러야 한다. 24: if ("c1" .equals(catalog)) 25: con.setCatalog("c1" ); 26: else 27: con.setCatalog("c2" ); 28: con.close(); 29: } catch (SQLException ex) { 30: System.err.println("SQLException Occured"); 31: } catch (NamingException e) { 32: System.err.println("NamingException Occured"); 33: } catch (FileNotFoundException e) { 34: System.err.println("FileNotFoundException Occured"); 35: } catch (IOException e) { 36: System.err.println("IOException Occured"); 37: } 38: }