Advertisement
Guest User

Untitled

a guest
May 4th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Logger logger = Logger.getLogger("MyLog");
  2. FileHandler fh;
  3. fh = new FileHandler("C:/Users/batam/Documents/MyLogFile.log");
  4. logger.addHandler(fh);
  5. SimpleFormatter formatter = new SimpleFormatter();
  6. fh.setFormatter(formatter);
  7.  
  8. Class.forName("oracle.jdbc.driver.OracleDriver");
  9.  
  10. Connection connection = null;
  11.  
  12. try {
  13. connection = DriverManager.getConnection(
  14. "jdbc:oracle:thin:@capmtr10:1521/FINDATA1", "bamat",
  15. "fg_3002");
  16.  
  17. } catch (SQLException e) {
  18.  
  19. e.printStackTrace();
  20.  
  21. return;
  22.  
  23. }
  24.  
  25. if (connection != null) {
  26.  
  27. try {
  28. String sql = "select a.userid, a.Description from USER_FINANCE a where a.userid = 'batam'";
  29.  
  30. Statement stmt = connection.createStatement();
  31.  
  32. ResultSet rs = stmt.executeQuery(sql);
  33.  
  34. while (rs.next()) {
  35.  
  36. String id = rs.getString("userid");
  37. String name = rs.getString("Description");
  38.  
  39. logger.info("Selecteds are : " + id + " : " + name);
  40. }
  41.  
  42. rs.close();
  43. stmt.close();
  44. } catch (SQLException e) {
  45. logger.info("SQLException : " + e.getMessage());
  46. } finally {
  47. try {
  48. connection.close();
  49. } catch (SQLException ex) {
  50. Logger.getLogger(IFS.class.getName()).log(Level.SEVERE, null, ex);
  51. logger.info("Close Exception : " + ex.getMessage());
  52. }
  53. }
  54.  
  55. } else {
  56. System.out.println("Failed to make connection!");
  57. logger.info("Failed to make connection!");
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement