“必须在ConnectionDriverName属性中指定JDBC驱动程序或DataSource类名。”错误

时间:2011-08-18 03:47:30

标签: java xml sqlite jpa

您好我正在尝试使用SQLite创建一个简单的JPA类。我已经设置了所有设置,然后每次尝试运行main时都会显示: “必须在ConnectionDriverName属性中指定JDBC驱动程序或DataSource类名。” 是因为我的sqlite驱动程序名称有错误的值吗? 我似乎无法找出sqlite属性的价值。这是我的persistence.xml:

    <?xml version="1.0"?>
<persistence>
    <persistence-unit name="testjpa" transaction-type="RESOURCE_LOCAL">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <class>entity.Discography</class>
        <properties>
            <property name="openjpa.ConnectionURL" value="jdbc:sqlite:C:\\sqlitedb\\repo.db" />
            <property name="openjpa.ConnectionDriverName" value="org.sqlite.JDBC" />
            <property name="openjpa.ConnectionUserName" value="" />
            <property name="openjpa.ConnectionPassword" value="" />
            <property name="openjpa.Log" value="SQL=TRACE" />
        </properties>
    </persistence-unit>
</persistence>

感谢您的帮助! :)

1 个答案:

答案 0 :(得分:-1)

org.sqlite.JDBC

您可以下载驱动程序here

使用这样的代码:

Class.forName("org.sqlite.JDBC"); // This doesn't actually do anything useful, it just asserts you can find the class
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement stat = conn.createStatement();
stat.executeQuery("select * from table");