Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public static void main(String[] args) {
  2. String host = "172.23.9.185";
  3. String port = "1521";
  4. String sid = "orcl";
  5. String user = "MHS175314019";
  6. String password = "MHS175314019";
  7. Connection conn = null;
  8.  
  9. try {
  10. Class.forName("oracle.jdbc.driver.OracleDriver");
  11. conn = DriverManager.getConnection("jdbc:oracle:thin:@" + host + ":" + port + ":" + sid, user, password);
  12.  
  13. String query = "select employee_id, first_name, last_name, email from employees";
  14. Statement st = conn.createStatement();
  15. ResultSet rs = st.executeQuery(query);
  16. while (rs.next()) {
  17. System.out.println(rs.getInt("employee_id") + "|" + rs.getString("first_name")
  18. + " " + rs.getString("last_name") + "|" + rs.getString("email"));
  19. }
  20. rs.close();
  21. st.close();
  22.  
  23. } catch (ClassNotFoundException ex) {
  24. System.out.println(ex.toString());
  25. } catch (SQLException ex) {
  26. System.out.println(ex.toString());
  27. } finally {
  28. try {
  29. conn.close();
  30. } catch (SQLException ex) {
  31. System.out.println(ex.toString());
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement