انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-026-L02

JdbcClient وJdbcTemplate

  • الدرس 2 من 5
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

run queries and updates without writing connection code.

الموضوعات المخطط لها

  • JdbcClient is the modern fluent API (Spring 6.1 and later); JdbcTemplate is the older, still common one.
  • Both open, close, and return connections for you.
  • Use named parameters (:name) instead of positional ? so queries stay readable.
  • .query(...) reads rows; .update(...) runs insert, update, delete and returns the affected row count.
  • A KeyHolder returns generated ids.
تفاصيل المخطط المبدئي

عرض عملي

java
int rows = jdbc.sql("update product set price = :price where id = :id")
        .param("price", newPrice)
        .param("id", id)
        .update();

Optional<Product> p = jdbc.sql("select id, name, price from product where id = :id")
        .param("id", id)
        .query(Product.class)
        .optional();

اختبر فهمك

What does update() return?

أظهر الإجابة

The number of affected rows.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.