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

من DriverManager إلى DataSource

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

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

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

في هذا الدرس

get database connections from a pool instead of opening one per statement.

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

  • JDBC is Java's standard API to talk to SQL databases; a driver (JAR) speaks the database's protocol.
  • DriverManager.getConnection(...) opens a brand-new connection each time: slow (network, login, setup).
  • A DataSource hands out connections; a pool (for example HikariCP) keeps them open and reuses them.
  • "Closing" a pooled connection returns it to the pool; always use try-with-resources.
  • Never open one connection per statement.
تفاصيل المخطط المبدئي

عرض عملي

java
try (Connection c = dataSource.getConnection();
     PreparedStatement ps = c.prepareStatement("select id, name from product where id = ?")) {
    ps.setLong(1, 42L);
    try (ResultSet rs = ps.executeQuery()) {
        if (rs.next()) System.out.println(rs.getString("name"));
    }
}

اختبر فهمك

What does close() do on a pooled connection?

أظهر الإجابة

Returns it to the pool; the real connection stays open.

التطبيق

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

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

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

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