I am having an issue with creating a database in my project. I've read in other topic, that I need to include this in my code:
Class.forName("org.apache.derby.jdbc.ClientDriver");
And so I did:
private static EntityManagerFactory factory;
public static Connection getConnection() {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
factory = Persistence.createEntityManagerFactory("Zadanie_3PU");
EntityManager em = factory.createEntityManager();
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/iab;create=true", "", "");
return con;
}
catch(Exception ex) {
System.out.println("Database.getConnection() Error -->" + ex.getMessage());
return null;
}
}
I've also made sure that I am loading the proper driver in my classpath:
And I also made sure that I have no typo in my persistence.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Zadanie_3PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>model.User</class>
<class>model.Email</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/iab;create=true"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
However, this keeps throwing me the following error on my glassfish server, when I am trying to run it:
Info: Database.getConnection() Error -->Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/iab;create=true
Error Code: 0
What am I doing wrong?