Advertisement
evofint

jdbc

Oct 1st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         ConnectionDB connectionDB = new ConnectionDB();
  6.         connectionDB.connect();
  7.        
  8.     }
  9. }
  10.  
  11. --------------------------------
  12. import java.sql.*;
  13.  
  14. public class ConnectionDB {
  15.     static final String driver = "oracle.jdbc.driver.OracleDriver";
  16.     static final String url = "jdbc:oracle:thin:@localhost:1521:orcle";
  17.  
  18.     static final String user = "evofint";
  19.     static final String password = "EVOFINT";
  20.  
  21.  
  22.  
  23.     public static void connect() {
  24.         Queries queries = new Queries();
  25.         try {
  26.             Class.forName(driver);
  27.             Connection connection = DriverManager.getConnection(url, user, password);
  28.             queries.queries(connection);
  29.         } catch(ClassNotFoundException e) {
  30.             e.printStackTrace();
  31.         } catch (SQLException e) {
  32.             e.printStackTrace();
  33.         }
  34.     }
  35. }
  36.  
  37. ---------------------------------
  38. import java.sql.ResultSet;
  39. import java.sql.SQLException;
  40. import java.sql.Statement;
  41.  
  42. public class Queries {
  43.  
  44. public static void queries(java.sql.Connection connection) throws SQLException {
  45.     Statement statement = connection.createStatement();
  46.     ResultSet resultSet = statement.executeQuery("select * from ADDRESSES");
  47.     while(resultSet.next()) {
  48.         String street = resultSet.getString("street_name");
  49.         String house = resultSet.getString("house_number");
  50.  
  51.         System.out.println("Улица: " + street);
  52.         System.out.println("Дом: " + house);
  53.     }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement