No suitable driver found (SQLite)

前端 未结 5 2037
夕颜
夕颜 2020-12-05 23:44

I hope someone can help me. I\'m working on a simple application which connects with an SQLite database. Following is my connection code:

try {           
           


        
5条回答
  •  遥遥无期
    2020-12-06 00:18

    I got the same problem. I used maven and added dependency:

        
            org.xerial
            sqlite-jdbc
            3.15.1
            
        
    

    It could be compiled and I got:

    No suitable driver found for jdbc:sqlite:xx.db

    I Checked the classpath and I was sure sqlite-jdbc-3.15.1.jar was there. I guess that for some reason, the Class was not loaded, I don't know why. so I added

    Class.forName("org.sqlite.JDBC");

    at the beginning of my code. It worked!

    And ,I delete the line above. It still works! I cleaned the project and rebuild it, no more Class.forName() is needed!!! I still Don't know why. But the problem is solved. I think Class.forName() can be used for diagnose if the class you need is in the classpath.

提交回复
热议问题