Guest User

Untitled

a guest
Jul 19th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package com.devcolibri.datavase;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.Driver;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8. public class Main {
  9. private static String driver = "com.mysql.jdbc.Driver";
  10. private final static String URL = "jdbc:mysql://localhost:3306/";
  11. private final static String DBNAME= "gregs_list";
  12. private final static String USERNAME ="root";
  13. private final static String PASSWORD ="root";
  14.  
  15. public static void main(String[] args) {
  16. Connection con ;
  17.  
  18. try {
  19. Class.forName(driver).newInstance();
  20. Connection conn = DriverManager.getConnection(URL+DBNAME,USERNAME,PASSWORD);
  21. if (conn != null)
  22. System.out.println ("Приложение подключилось к БД !");
  23. else
  24. System.out.println ("Приложение НЕ подключилось к БД ?");
  25.  
  26. conn.close();
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. <?xml version="1.0" encoding="UTF-8"?>
  34. <project xmlns="http://maven.apache.org/POM/4.0.0"
  35. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  36. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  37. <modelVersion>4.0.0</modelVersion>
  38.  
  39. <groupId>com.devcolibri</groupId>
  40. <artifactId>com.devcolibri.databaseexam</artifactId>
  41. <version>1.0-SNAPSHOT</version>
  42.  
  43. <dependencies><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  44. <dependency>
  45. <groupId>mysql</groupId>
  46. <artifactId>mysql-connector-java</artifactId>
  47. <version>8.0.11</version>
  48. </dependency>
  49. </dependencies>
  50. </project>
Add Comment
Please, Sign In to add comment