HOW DO YOU CONNECT TO THE DATABASE IN JAVA ?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
 575  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    How do you connect to the Database in Java ?

    The process of using JDBC to connect to the database is as follows:

    Register the driver: Class.forName(”driverName”); For example, sun.jdbc.odbc.JdbcOdbcDriver
    Connection con = DriverManager.getConnection(”url,”myLogin”,myPassword”);
    For example url may be jdbc:odbc:dsn_name.
    Creating the JDBC Statement and Retreiving:
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!