Advertisement
samuel34

Untitled

Jun 1st, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Connectivity {
  4. static final String DRIVER = "com.mysql.jdbc.Driver";
  5. static final String DB_URL = "jdbc:mysql://localhost/demo";
  6. //database credentials
  7. static final String Uname = "root";
  8. static final String Pass = "#Tandy1997";
  9. public static void main(String[] args) {
  10. Connection conn = null;//connection object.
  11.  
  12. //Register our driver
  13. try{
  14. Class.forName("com.mysql.jdbc.Driver") ;
  15. System.out.println("connecting to database...");
  16. conn = DriverManager.getConnection(DB_URL,Uname,Pass);
  17. }catch(SQLException e){System.out.println("An error occured "+e.getErrorCode());}
  18. catch(Exception e){
  19. System.out.println(e.getMessage());
  20. }
  21. finally{
  22. //close Resources.
  23. try{
  24. if(conn!=null){
  25. conn.close();}
  26. }catch(SQLException e){
  27. System.out.println(e.getMessage());
  28. }
  29. }
  30. }
  31. }
  32.  
  33.  
  34. Look at the Error log...
  35.  
  36. Error: Main method not found in class Connectivity, please define the main method as:
  37. public static void main(String[] args)
  38. or a JavaFX application class must extend javafx.application.Application
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement