Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.Connection;
  3. import java.sql.SQLException;
  4.  
  5. public class JDBCExample {
  6.  
  7. public static void main(String[] argv) {
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException e) {
  11. System.out.println("Where is your MySQL JDBC Driver?");
  12. e.printStackTrace();
  13. return;
  14. }
  15.  
  16. Connection connection = null;
  17.  
  18. try {
  19. connection = DriverManager
  20. .getConnection("jdbc:mysql://localhost:3306/TABELA","USERNAME", "PASSWORD");
  21.  
  22. } catch (SQLException e) {
  23. System.out.println("Connection Failed!");
  24. e.printStackTrace();
  25. return;
  26. }
  27.  
  28. if (connection != null) {
  29. System.out.println("Connection Successful!");
  30. } else {
  31. System.out.println("Failed to connect!");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement