为了账号安全,请及时绑定邮箱和手机立即绑定

没有找到适合“jdbc:sqlite:myDB.sqlite”的驱动程序

没有找到适合“jdbc:sqlite:myDB.sqlite”的驱动程序

富国沪深 2021-10-28 09:14:21
我正在尝试编写一个 java 应用程序以使用 maven 连接到内存中的 sqlite db。我也向 pom.xml 文件添加了 SQLite 依赖项。当我运行程序时,我收到错误:“java.lang.ClassNotFoundException: org.sqlite.JDBC”和“没有找到适合 jdbc:sqlite:myDB.sqlite 的驱动程序”。请让我知道我是否遗漏了什么。谢谢你!public class Application {  public static void main(String[] args) throws  ClassNotFoundException{    System.out.println("Application class created\n");    Connection connection = null;    try {        Class.forName("org.sqlite.JDBC");    }catch (ClassNotFoundException e){        System.err.println("Class not found"+e);    }    try{        connection = DriverManager.getConnection("jdbc:sqlite::memory:");        Statement statement = connection.createStatement();        statement.setQueryTimeout(33);        statement.executeUpdate("create table demo (id integer, name string)");        statement.executeUpdate("insert into demo(1, 'A')");        ResultSet mySet = statement.executeQuery("select * from demo");        while(mySet.next()){            System.out.println("Name is : "+mySet.getString("name"));            System.out.println("Id is : "+mySet.getInt("id"));        }    }    catch (SQLException sqlException){        System.err.println(sqlException.getMessage());    }    finally {        try{            if(connection!=null)                connection.close();        }        catch (SQLException sqlException){            System.err.println(sqlException);        }    }}}我的 POM 文件依赖是:  <properties>    <maven.compiler.source>1.8</maven.compiler.source>    <maven.compiler.target>1.8</maven.compiler.target></properties><!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc --><dependencies>    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->    <dependency>        <groupId>org.xerial</groupId>        <artifactId>sqlite-jdbc</artifactId>        <version>3.23.1</version>    </dependency>
查看完整描述

1 回答

?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

删除 maven-jar-plugin


并使用此插件生成包含所有依赖项的 jar,并运行 jar-with-dependencies


<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-assembly-plugin</artifactId>

    <executions>

        <execution>

            <phase>package</phase>

            <goals>

                <goal>single</goal>

            </goals>

            <configuration>

                <archive>

                    <manifest>

                        <mainClass>

                            your.main.Class

                        </mainClass>

                    </manifest>

                </archive>

                <descriptorRefs>

                    <descriptorRef>jar-with-dependencies</descriptorRef>

                </descriptorRefs>

            </configuration>

        </execution>

    </executions>

</plugin>


查看完整回答
反对 回复 2021-10-28
  • 1 回答
  • 0 关注
  • 145 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信