Saturday 9 August 2014

JDBC : Load JDBC Driver


















Click here to watch in Youtube : https://www.youtube.com/watch?v=fA539fwWtHY

Click the below Image to Enlarge
JDBC : Load JDBC Driver
JDBC : Load JDBC Driver
JDBC : Load JDBC Driver
JDBC : Load JDBC Driver
JDBC : Load JDBC Driver
JDBC : Load JDBC Driver
LoadJDBCDriver.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class LoadJDBCDriver
{
    private Connection connection = null;

    public static void main( String[] args )
    {
        try
        {
            LoadJDBCDriver loadJDBCDriver = new LoadJDBCDriver();
            loadJDBCDriver.loadDriver();
        }
        catch( ClassNotFoundException | SQLException e )
        {
            e.printStackTrace();
        }

    }

    private void loadDriver() throws ClassNotFoundException, SQLException
    {
        /*
         * This will load the MySQL driver and Register the Driver in DriverManager, each DB has its own driver
         */

        Class.forName("com.mysql.jdbc.Driver");

        /*
         * Setup the connection with the DB.
         */

        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/world", "root", "root");

        System.out.println("Connection Object :  " + connection);
    }

}

Output
Connection Object :  com.mysql.jdbc.JDBC4Connection@1aa159bb

Environment Used 

JDK version : 1.7.0_51
Mysql Server version : 5.6.19 

To Download LoadJDBCDriverDemoApp Project Click the below link

https://sites.google.com/site/javaee4321/jdbc/LoadJDBCDriverDemoApp.zip?attredirects=0&d=1

See also:

  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment