Advertisement
far_light

Database

Mar 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Connection connect;
  8.        
  9.         try {
  10.             Class.forName("com.mysql.jdbc.Driver");
  11.            
  12.             String serverName = "localhost",
  13.                     databaseName = "it-learning",
  14.                     url  = "jdbc:mysql://" + serverName + "/" + databaseName,
  15.                     user = "root",
  16.                     password = "";
  17.            
  18.             connect = DriverManager.getConnection(url, user, password);
  19.             String query = "SELECT * FROM courses";
  20.             Statement statement = connect.createStatement();
  21.             ResultSet set = statement.executeQuery(query);
  22.            
  23.             while (set.next()) {
  24.                 System.out.println(set.getString("icon"));
  25.             }
  26.            
  27.             connect.close();
  28.         } catch (Exception e) {
  29.             e.printStackTrace();
  30.         }
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement