1: package testbed.unsafe; 2: import java.io.FileInputStream; 3: import java.io.FileNotFoundException; 4: import java.io.IOException; 5: import java.sql.Connection; 6: import java.sql.DriverManager; 7: import java.sql.SQLException; 8: public class U260 { 9: public boolean connectTest(String url, String usr) { 10: Connection con = null; 11: byte[] b = new byte[1024]; 12: boolean result = false; 13: try { 14: FileInputStream fs = new FileInputStream("sample.cfg"); 15: // 외부데이터를 배열로 읽어온다. 16: fs.read(b); 17: // 패스워드 문자열을 만든다 18: String password = new String(b); 19: // 패스워드가 DB 연결정보로 사용이 된다. 20: con = DriverManager.getConnection(url, usr, password); 21: } catch (FileNotFoundException e) { 22: System.err.println("File Not Found Exception Occurred!"); 23: } catch (IOException e) { 24: System.err.println("I/O Exception Occurred!"); 25: } catch (SQLException e) { 26: System.err.println("SQL Exception Occurred!"); 27: } finally { 28: try { 29: if (con != null) { 30: con.close(); 31: result = true; 32: } 33: } catch (SQLException e) { 34: System.err.println("SQL Exception Occurred!"); 35: } 36: } 37: return result; 38: } 39: }