All IT Courses 50% Off
QA Tutorials

How to connect Database using JDBC?

There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.

Below are the steps: 

  1. Load and register the driver
  2. Establish connection
  3. Creating statement object
  4. Execute the statement
  5. Closing the connection
  1. Load and register the driver

For registering the driver we load the driver class using the name forName() method. This method loads the class which is mentioned as parameter.

Class.forName(“com.mysql.jdbc.Driver");
// class.forName load the Driver class
  1. Establishing the Connection:

For establishing connection with database static method called getConnection () is activated which is present in DriverManagerClass it has three arguments of string type URL, username and password.

DriverManager.getConnection (“jdbc:mysql://localhost:3306 Employee”,"root","root");

URL contains JDBC (main protocol): MySQL (sub protocol for  mySql)://localhost:3306(sub name for mySql(host:prot)/Employee(database) when this method returns an connection object that is

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Employee","root","root"); 
  1. Creating statement object

For creating statement object a method is called createStatement() which is called present connection interface.

con.createStatement();

which returns the object with no argument like

Statement st= con.createStatement();
  1. Executing Queries

For executing queries there are different methods in statement interface by retrieving records and updating records. For fetching queries we call method like executeQuery (string qry) by taking string as parameter.

st.executeQuery ("Select * from Employee");

This returns the object as resultset object

Resultset rs= st.executeQuery ("Select * from Employee”);

// once executeQuery() executes the query and stores the records in to ResultSet object.

  1. Close connection
Facebook Comments

12 Comments

  1. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector.
    It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    The steps are Load and register the driver , Establish connection , Creating statement object , Execute the statement ,
    Closing the connection

  2. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.

    Below are the steps:

    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  3. How to connect Databases using JDBC?
    JDBC (Java Database Connectivity) is the Java API that manages connecting to a database, issuing queries and commands, and handling result sets obtained from the database.
    There are steps for database connectivity. Before proceeding, you need to have a MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.

    Below are the steps:
    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  4. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.

    Below are the steps:

    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  5. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.

    Below are the steps:

    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  6. For connectivity of database we need to have
    – MySQL connector.: It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Steps for database connectivity:
    1. Load and register the driver
    2. Establish connection
    3. Creating statement object
    4. Execute the statement
    5. Closing the connection

  7. There are steps for connectivity of database.You need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  8. Here are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

  9. How to connect Database using JDBC?
    There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    1. Load and register the driver
    2. Establish connection
    3. Creating statement object
    4. Execute the statement
    5. Closing the connection
    1. Load and register the driver
    For registering the driver we load the driver class using the name forName() method. This method loads the class which is mentioned as parameter.
    1.Establishing the Connection:
    2. Creating statement object
    3. Executing Queries

  10. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    1. Load and register the driver
    2. Establish connection
    3. Creating statement object
    4. Execute the statement
    5. Closing the connection

  11. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    1. Load and register the driver
    2. Establish connection
    3. Creating statement object
    4. Execute the statement
    5. Closing the connection

  12. There are steps for connectivity of database. Before proceeding, you need to have MySQL connector. It can be downloaded from Download MySQL connector Jar and add it as a build path by adding Selenium web driver jar.
    Below are the steps:
    Load and register the driver
    Establish connection
    Creating statement object
    Execute the statement
    Closing the connection

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close

Get Python Course
worth 499$ for FREE!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys Blog will use the information you provide on this form to be in touch with you and to provide updates and marketing.