Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1.  
  2. public class GetTweets {
  3.     public GetTweets(MysqlDB database) {
  4.         this.database = database;
  5.     }
  6.    
  7.     private final MysqlDB database;
  8.    
  9.     public static void main(String[] args) throws SQLException {
  10.         Connection conn = DriverManager.getConnection(
  11.             "jdbc:mysql://domU-12-31-38-00-8E-18.compute-1.internal/daphnie",
  12.             "daph_admin",
  13.             "gU3:35"
  14.         );
  15.         try {
  16.             MysqlDB database = new MysqlDB(conn);
  17.             GetTweets getTweets = new GetTweets(database);
  18.             getTweets.run(args);
  19.         } finally {
  20.             conn.close();
  21.         }
  22.     }  
  23.    
  24.     public void run() {
  25.         ResultSet brands = database.getSearchNames();
  26.         try {
  27.             while(brands.next()) {
  28.                 String brand_name = brands.getString("name");
  29.                 System.out.println(brand_name);
  30.             }
  31.         } catch (SQLException e) {
  32.             System.out.println("Query Error " + e);
  33.         } finally {
  34.             brands.close();
  35.         }
  36.     }  
  37. }
  38.  
  39. public class MysqlDB {
  40.         public MysqlDB(Connection connection) {
  41.             this.connection = connection;
  42.         }
  43.        
  44.         public ResultSet getSearchNames() throws SQLException {
  45.             // Not perfect: no finally block for stmt.
  46.             Statement stmt = conn.createStatement();
  47.             return stmt.executeQuery("SELECT name from brands");
  48.         }
  49.    
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement