Advertisement
Guest User

Untitled

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