Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1.    public static void main(String[] args) throws Exception {
  2.         MySQLAccess dao = new MySQLAccess();
  3.         dao.readDataBase();
  4.     }
  5.  
  6. -------------
  7.  
  8.  
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.sql.Statement;
  15. import java.util.Date;
  16.  
  17. public class MySQLAccess {
  18.  
  19.     public void readDataBase() {
  20.         String url = "jdbc:mysql://mysql.wmi.amu.edu.pl:3306/s434596_javapizza";
  21.         String userName = "s434596";
  22.         String password = "tinwordpress123";  
  23.        
  24.         //MySQLAccess.forName(driver).newInstance();
  25.         try {
  26.         Class.forName("com.mysql.jdbc.Driver");
  27.         } catch (ClassNotFoundException s) {
  28.             throw new IllegalStateException("Cannot find the driver in the classpath!", s);
  29.         }
  30.         System.out.println("Connecting database...");
  31.  
  32.         try (Connection connection = DriverManager.getConnection(url, userName, password)) {
  33.             System.out.println("Database connected!");
  34.         } catch (SQLException e) {
  35.             throw new IllegalStateException("Cannot connect the database!", e);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement