Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Connectivity {
- static final String DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost/demo";
- //database credentials
- static final String Uname = "root";
- static final String Pass = "#Tandy1997";
- public static void main(String[] args) {
- Connection conn = null;//connection object.
- //Register our driver
- try{
- Class.forName("com.mysql.jdbc.Driver") ;
- System.out.println("connecting to database...");
- conn = DriverManager.getConnection(DB_URL,Uname,Pass);
- }catch(SQLException e){System.out.println("An error occured "+e.getErrorCode());}
- catch(Exception e){
- System.out.println(e.getMessage());
- }
- finally{
- //close Resources.
- try{
- if(conn!=null){
- conn.close();}
- }catch(SQLException e){
- System.out.println(e.getMessage());
- }
- }
- }
- }
- Look at the Error log...
- Error: Main method not found in class Connectivity, please define the main method as:
- public static void main(String[] args)
- or a JavaFX application class must extend javafx.application.Application
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement