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
How to connect to a database in Java
More Relevant Posts
-
Working with byte[] data is common in Java applications — for example, when reading input streams, files, or network responses. In many cases, you may need to convert this binary data into a URI (Uni https://lnkd.in/dTEdrdeF
To view or add a comment, sign in
-
In modern Java applications, generating dynamic text is a common need — whether it’s building personalized email content, log messages, SQL queries, or configuration templates. Templating and placehol https://lnkd.in/d8_XFUgg
To view or add a comment, sign in
-
🚀 Modern Java Feature for Auto-Closing Database Connections 🤔 Are you still closing DB connections manually? Wait.... use Try-With-Resources, the Java’s smarter way to manage cleanup 👇 When you open a file, stream, or connection, you must close it to prevent leaks. ❌ Before Java 7, we did it the hard way 👇 BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("data.txt")); System.out.println(reader.readLine()); } finally { if (reader != null) reader.close(); } ✅ Then came Try-With-Resources — 🔥No finally block 👇 BufferedReader reader = new BufferedReader(new FileReader("data.txt")); try (reader) { System.out.println(reader.readLine()); } 💡 How it works 👇 🔹Any class implementing AutoCloseable (like BufferedReader) can go inside try(). 🔹JVM automatically calls close() when the block ends, even on exceptions. 💬 What do you think ? #ModernJava #JavaDeveloper #CleanCode #ProgrammingTips #DevelopersCommunity #CodeSmarter
To view or add a comment, sign in
-
When you code in Java, the appeal of the work lies in the use of Generics. For example, when we have a class : public class Response<T> { private ResponseError error; private T response; private Map<String, Object> additionalProperties; } Now, if we want to use this class as a response for calling an external service, how would we do it? @PostMapping(value = "${feignClients.example-url-address}", produces = "application/json", consumes = "application/json") Response<exampleResponse> getInfo(@Valid @RequestBody exampleRequest request); In this case, if we don't define the response object or exampleResponse properly, we won't be able to map the response returned by the service correctly. The outer Response<> type has a field called response. so Jackson puts this part of the JSON into that field. So, if you define the service response class like this: private ٍExampleError error; private ExampleResponseData response; Therefore you get the error: Unrecognized field "someResponse" Since your API already wraps everything in an "error" and "response" field, you don’t need another Response<> wrapper in your Feign client.If your project uses a global Response<T> wrapper for all Feign clients, then you must change the generic type parameter so it matches the actual JSON structure. The "Unrecognized field" error is quite simple but useful. 🙂 In the comment, share your experiences in this area. 😊 #JSON #JACKSON #GENERICS #JAVA
To view or add a comment, sign in
-
Today I explored one of the most useful Java features — Try-With-Resources This feature automatically closes resources (such as files, readers, writers, and database connections) and prevents memory leaks. It makes code cleaner, safer, and more efficient. Here’s a simple example where I created a file on the Desktop and wrote data into it using Try-With-Resources package com.collection; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class TrywithResouce { public static void main(String[] args) { String str = " happy codeing..."; String path = "C:\\Users\\Anish-bin-Shakil\\Desktop\\str.txt"; try (BufferedWriter br = new BufferedWriter(new FileWriter(path))) { br.write(str); br.newLine(); } catch (IOException e) { e.printStackTrace(); } System.out.println("data written successfully"); } } ✨ Key Benefits of Try-With-Resources: ✅ Automatic resource closing ✅ No need to call .close() manually ✅ Cleaner & safer code ✅ Reduces chances of memory/resource leaks ✅ Better exception handling I’m enjoying learning and improving my Java skills every day! #Java #TryWithResources #FileHandling #CodingInJava #LearningEveryday #SoftwareDevelopment #FreshersJourney #JavaDeveloper
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development