What does 'Class.forName(“org.sqlite.JDBC”);' do?

前端 未结 2 1549
离开以前
离开以前 2020-12-03 10:35

I am trying to create a simple app with a SQLite database. I chose to use the SQLiteJDBC driver.

The code below is taken from the above website. My question is abou

2条回答
  •  北海茫月
    2020-12-03 10:47

    The Class.forName statement is making sure that the class that implements the JDBC driver for sqlite3 is loaded and registered with the JDBC factory mechanism.

    When you call DriverManager.getConnection(), it looks for classes that are registered and claim to be able to handle the connection string. If no such class is found, it can't create the connection.

提交回复
热议问题