Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A brief explanation : how JDBC works? [closed]

Tags:

java

jdbc

can anyone in simple words explain what exactly the "steps" in implementing a JDBC mean? What is the importance of each step? Why DriverManager class is required? what is it? What is a Driver in first place? what does it do? Basically I want the internal working of JDBC (with respect to MySqL) , and how is it carried out? And also while connecting java with MySql, what is the importance of port? and why is username and password required?

like image 492
user2056245 Avatar asked Apr 26 '13 01:04

user2056245


People also ask

Where does JDBC connection close?

Closing the JDBC Connection Once you are done using the database connection you should close it. This is done by calling the Connection. close() method, like this: connection.

Why we close the connection in JDBC?

If the database sever grants all of them, and after their usage they are not closed, the database server would not be able to provide any other connection for another request. For that reason we need to close them - it is mandatory.

How is JDBC connection done?

Typically, a JDBC application connects to a target data source using one of two classes: DriverManager : This fully implemented class connects an application to a data source, which is specified by a database URL.

Which method is used to close the database connection?

The close() / mysqli_close() function closes a previously opened database connection.


1 Answers

Why DriverManager class is required? what is it?

The DriverManager is registry and lookup mechanism. It is responsible for taking the database connection URL and finding a suitable driver capable of using it.

The DriverManager is used to maintain a single instance of each driver, which reduces the number of resources required and prevents the need for having multiple instances of the same driver running in memory...

For example, the general URL for MySQL starts with jdbc:mysql://. The DriverManager asks each driver if it understands the URL, when it finds one, it passes the URL to it to create the actual connection.

What is a Driver in first place? what does it do?

The driver is a contract between your application and the database. It is a means by which it's possible to write standardized code that can be used against multiple databases, which doesn't actually need to know or care how those calls are physically made to the database.

And also while connecting java with MySql, what is the importance of port?

This is a very basic concept of communication between computers. Think of a computer as a block of units. In order to send a letter to this computer, you need an address, this would be the computers IP address. You also need to know the unit you are sending the letter to, this is the port number.

This allows you to talk with not only the computer, but an individual process. Life would be pretty difficult if you could only talk to one process.

and why is username and password required?

This comes down security. It describes not only who can connect to a particular database, but what they can do, like insert, update, delete and create database objects.

like image 82
MadProgrammer Avatar answered Sep 20 '22 08:09

MadProgrammer