Home > DeveloperSection > Interviews > How do you connect to the Database in Java ?

Posted on    July-16-2015 10:05 PM

 Java Java  Database Connection 
 1 Answer(s)
  534  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    July-16-2015 10:05 PM

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);

Don't want to miss updates? Please click the below button!

Follow MindStick