can we use anything else instead of Class.forName()
for loading a driver for jdbc connectivity
i.e is first step of jdbc connection?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
can we use anything else instead of "Class.forname" for loading a driver for jdbc connectivity i.e is first step of jdbc connection?
You haven't even needed that since JDBC 4.1. Just call DriverManager.getConnection()
with an appropriate URL.
回答2:
Just import java.sql.Driver
and invoke DriverManager.getConnecion()
to establish a database connection. You don't really need to call Call.forName()
these days (java7).
回答3:
Use Spring's JDBCTemplate; it's a best practice.