Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why not statically import a database driver class?

0
Posted

Why not statically import a database driver class?

0

The standard import statement makes a class available to the importing class to use its public variables and method calls. It is certainly possible to import specific JDBC driver implementations and use them in the same way, provided they are available on the application’s classpath. However, the Java SQL package and JDBC scheme has been designed to deal with database interfaces in a generic way that is not tied to any single driver implementation. In fact, it is possible to load multiple drivers in a single application. Though it may be possible to load a specific driver and invoke its connect(String, Properties) method directly, it is far preferable to use the static Class.forName(String) method and get connections through the DriverManager’s getConnection() methods. This allows you to configure your application’s database driver using external configuration or properties, rather than hard code class references. You only need declare the Java interface types for the driver, connectio

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123