Advertisement
koalasuccess

java sql ex 2

Mar 28th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package exercises;
  2.  
  3. import java.sql.*;
  4.  
  5. public class JDBCex2 {
  6. static Connection conn = null;
  7. static Statement stmt = null;
  8. static String dbURL = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
  9. static String user = "labs";
  10. static String password = "labs";
  11.  
  12.  
  13. public JDBCex2() { }
  14.  
  15. public static void main (String args[]) throws SQLException {
  16. try {
  17. conn = DriverManager.getConnection(dbURL, user, password);
  18. conn.clearWarnings();
  19. System.out.println("Connection opened! For driver ==>Oracle 11XE");
  20. stmt = conn.createStatement();
  21. ResultSet rs = stmt.executeQuery("select * from customers");
  22.  
  23. while (rs.next()) {
  24. System.out.println(rs.getString(2) + " " + rs.getString("CUSTLASTNAME"));
  25. }
  26.  
  27. rs.close();
  28. } catch (SQLException e) {
  29. System.err.println(e.getMessage());
  30. } finally {
  31. if (!conn.isClosed()) {
  32. conn.close();
  33. System.out.println("Connection closed! Oracle");
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement