How to connect to a database in Java

Hello people 💫 🔰 Advanced java ❇️ Steps to connect with the Database : 💠 Loading the driver 💠 Establishing the connection 💠 Create a statement 💠 Execute the statement 💠 Close the connection ✅ Loading the driver : It adds the jar(implementation class,interfaces,methods) files to project files. 🔸 By using Class.forName("com.mysql.cj.jdbc.Driver"); It uses the package : java.sql package ✅ Establishing the connection : It is a connection interface 🔸 By using Object Creation Connection connect = DriverManager.getconnection(String url, username, password); *️⃣ The url, username, password are the parameters ✅ Create a statement : It is a Statement interface 🔸 By using create statement method Statement statement = Connection. create statement(); This statement is present inside the connection ✅ Execute the statement : It consists of three types 🔸 Execute(); 🔸 Execute update(); 🔸 Execute query(); 🔸 Execute() : It is mostly used in ddl commands It returns the boolean Statement.execute();//return boolean 🔸 Execute update() : It is mostly used in dml commands It returns int value Statement.execute update();//return int value 🔸 Execute Query() : Mostly used in dql commands It returns the result set Result Set : It is a Interface which is used to store interface from the database Statement.Executequery();//return result set ✅ Close the connection : By using close methos we can close the connection connection. close(); Thank you, Uppugundla Sairam sir, Saketh Kallepu sir,Levaku Lavanya mam #javafullstack #advancedjava #stepstoconnectwithdatabase

To view or add a comment, sign in

Explore content categories