0
votes

I have a simple program using JPA entities to write into a Derby DB (the entities were generated from an existing DB tables). I am using Eclipse and there is a working connection between the Derby client and the server via the EclipseLink Data Source Explorer .

Here is the start of my main():

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.*;
import javax.*;

public class start {

    /**
     * @param args
     */
    private static final String PERSISTENCE_UNIT_NAME = "zodiac";
    private static EntityManagerFactory factory;

    public static void main(String[] args) {
    try {
        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        EntityManager em = factory.createEntityManager();
        System.out.println("after factory gen" );

when I the line with createEntityManager() is executed the following exception is thrown:

[EL Info]: 2012-03-07 22:46:21.892--ServerSession(253038357)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461 [EL Severe]: 2012-03-07 22:46:22.064--ServerSession(253038357)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No suitable driver Error Code: 0

Any idea what is the problem ? thanks

1

1 Answers

0
votes

If you're in Eclipse you need to add the driver to your project classpath. Sounds like you already have a datasource so you must have defined the driver library. All you need to do is "Add Library" to your Java Build Path and choose "Connectivity Driver Definition" and then the Derby driver from the drop down list of available driver definitions.

FYI, there's a checkbox in the New JPA Project wizard where you can select "add driver to classpath" to do this when you create a new project.

Of course you can also add the derbyclient.jar to your classpath directly or define a user library that includes it.

--Shaun