JdbcClient وJdbcTemplate
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
run queries and updates without writing connection code.
الموضوعات المخطط لها
JdbcClientis the modern fluent API (Spring 6.1 and later);JdbcTemplateis 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
KeyHolderreturns generated ids.
تفاصيل المخطط المبدئي
عرض عملي
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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.