Welcome to

w3study.github.io




Topics

CRUD Operation using JDBC API



CRUD Operation Using JDBC API in Hindi


CRUD Operation Using JDBC API

JDBC (Java Database Connectivity) API का उपयोग Java में database से connect करने और CRUD (Create, Read, Update, Delete) operation को perform करने के लिए किया जाता है।

JDBC driver का उपयोग करके Java application को database से जोड़ा जाता है।

database connection के लिए DriverManager.getConnection(url, username, password) का उपयोग किया जाता है।

Statement/PreparedStatement का उपयोग SQL query को run कराने के लिए किया जाता है।

Create (Insert Operation) के लिए INSERT INTO table_name (columns) VALUES (values) SQL Query का उपयोग किया जाता है।

java

String query = "INSERT INTO students (id, name, age) VALUES (?, ?, ?)";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1, 101);
ps.setString(2, "Rahul");
ps.setInt(3, 21);
ps.executeUpdate();

Read (Select Operation) के लिए SELECT * FROM table_name SQL query का उपयोग किया जाता है।

java

String query = "SELECT * FROM students";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
    System.out.println(rs.getInt("id") + " " + rs.getString("name") + " " + rs.getInt("age"));
}

Update (Update Operation) के लिए UPDATE table_name SET column=value WHERE condition SQL query का उपयोग किया जाता है।

java

String query = "UPDATE students SET age = ? WHERE id = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1, 22);
ps.setInt(2, 101);
ps.executeUpdate();

Delete (Delete Operation) के लिए DELETE FROM table_name WHERE condition SQL query का उपयोग किया जाता है।

java

String query = "DELETE FROM students WHERE id = ?";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1, 101);
ps.executeUpdate();

Exception Handling के लिए try-catch का उपयोग किया जाता है ताकि SQL और कनेक्शन error को handle किया जा सके।

Connection Close करना ज़रूरी होता है ताकि resources free हो जाएं।

java

con.close();

JDBC steps में सबसे पहले driver load करना, connection बनाना, statements तैयार करना, SQL execute करना और connection बंद करना शामिल होता है।

  • Database Connection in Hindi

  • Advanced Java Notes in Hindi"
  • Development of Android Applications Notes in Hindi


  • Request:

    हैलो दोस्तों! उम्मीद करता हूं आपको हमारा यह content/post पसंद आया होगा। अगर आपको हमारा ये content/post पसंद आई हो तो अपने दोस्तों के पास भी share करे। और अगर आपको कोई problem या कोई specific content हिन्दी में चाहिए है तो आप हमें नीचे दिए गए Email या whatsapp number के जरिए बता सकते है।

    अगर आप CCC/diploma/polytechnic/MCA/BCA etc कर रहे है तो ये website स्पेशली आपके लिए ही है, जो student हिंदी में पढ़ाई करते है।

    Contact Us

    Email: deepanshuranjan8057@gmail.com

    Whatsapp: +91 8057754706



    Follow Us

    Facebook Logo    Instagram Logo