---
title: "How do you connect to the Database in Java ?"  
description: "How do you connect to the Database in Java ?"  
author: "Anonymous User"  
published: 2015-07-16  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/2708/how-do-you-connect-to-the-database-in-java  
category: "java"  
tags: ["java", "database connection"]  
reading_time: 1 minute  

---

# 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.JdbcOdbcDriverConnection 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);
```

## Answers

### Answer by Anonymous User

The process of using JDBC to connect to the database is as follows:\

```
Register the driver: Class.forName(”driverName”); For example, sun.jdbc.odbc.JdbcOdbcDriverConnection 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);
```


---

Original Source: https://www.mindstick.com/interview/2708/how-do-you-connect-to-the-database-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
