In our last tutorial, we discussed Socket Programming in Java. Here, we are going to learn about what is JDBC Connection in Java. Moreover, we will discuss important detail related to Java Database Connectivity. At last, we will see various JDBC connection steps involved in the creation of the connection and many other things.
So, let us start JDBC Connection in Java.
JDBC is an acronym for Java Database Connectivity. It’s a headway for ODBC (Open Database Connectivity). JDBC Connection in Java is a standard API particular created with a specific end goal to move information from frontend to backend. This Java API comprises of classes and interfaces written in Java. It fundamentally goes about as an interface (not the one we use in Java) or channel between your Java program and databases i.e. JDBC connection in Java, sets up a connection between the two with the goal that a developer could send information from Java code and store it in the database for some time later.
Why JDBC Connection in Java came into existence?
As beforehand told JDBC is a headway for ODBC, ODBC being stage subordinate had a ton of downsides. ODBC API was composed in C, C++, Python, and Core Java and as we probably are aware above dialects (aside from Java and some piece of Python) are stage subordinate. Accordingly, to expel reliance, JDBC connection in Java was created by database merchant which comprised of classes and interfaces written in Java.
user – username from which your sql summon provoke can get to.
password – watchword from which your sql summon provoke can get to.
con- is a reference to Connection interface.
Where Oracle database utilize, thin is the driver utilized, @localhost is the IP Address where a database is put away, 1521 is the port number and xe is the specialist organization. Every one of the 3 parameters above is of String write and are to be announced by software engineer before calling the capacity. Utilization of this can allude from conclusive code.
Once an association is built up you can collaborate with the database. The JDBC Statement, CallableStatement, and PreparedStatement interfaces characterize the strategies that empower you to send SQL summons and get information from your database.
Here, coa n is a reference to Connection interface utilized as a part of past advance.
Query for refreshing/embeddings table in a database.
The executeQuery() technique for Statement interface utilizes to execute questions of recovering esteems from the database. This strategy restores the protest of ResultSet that can utilize to get every one of the records of a table.
The executeUpdate(sql inquiry) technique of Statement interface utilize to execute inquiries of refreshing/embeddings.
So at long last, we have sent the information to the predetermined area and now we are at the skirt of a fulfillment of our undertaking.
By shutting association, objects of Statement and ResultSet will shut naturally. The nearby() technique for Connection interface is utilize to close the association.
This was all about JDBC Connection in Java Tutorial. Hope you like our explanation.
Hence, in this Java tutorial, we learned what is JDBC Connection in Java and how to establish JDBC connection in Java between Java program and Database with an example program. Furthermore, if you have any query feel free to ask in the comment section.