Driver name for derby 10.7 in-memory - java

Can any one tell the driver name for derby 10.7 in memory mode?
We are using below for in-memory:
org.apache.derby.jdbc.EmbeddedDriver
and below for filesystem based (for previous derby version):
org.apache.derby.jdbc.ClientDriver
I found that for 10.7 , file-system based, driver name should be:
org.hibernate.dialect.DerbyTenSevenDialect
So is there any change for in-memory driver name?

You can access an in-memory database via the embedded driver or the network driver if the in-memory db is exposed to the network. You have to specify the JDBC connection URL correctly though.
http://db.apache.org/derby/docs/10.11/devguide/cdevdvlpinmemdb.html

I don't understand your terminology. Derby has two different environments in which it can run: Embedded, and Client/Server. See: http://db.apache.org/derby/docs/10.8/getstart/cgsquck70629.html
The JDBC driver names that you have (EmbeddedDriver and ClientDriver) are correct. http://db.apache.org/derby/docs/10.8/getstart/rgsquck35368.html
It looks like you are including Hibernate in your application, as DerbyTenSevenDialect is a Hibernate class, not a Derby class. You need to consult the Hibernate community and documentation for Hibernate information.

Related

How can I find all JDBC drivers available?

I have a library method that can be used to connect to a database and then build a document using data from the database.
When they run this app with no parameters, I want to list out all available sql vendor connections. Based on this question I'm guessing its done using ServiceLoader but it's not clear to me exactly how to do this.
And critical to this is I'd like to get the class "com.mysql.jdbc.Driver", and I must get the "jdbc:mysql:" start of the connection string syntax.
So, how can I get the class (optional) and connection string start (necessary) of all JDBC connectors in the classpath?
There is no way defined in JDBC to automatically discover the JDBC URL format of a driver.
You will need to keep a registry of JDBC URL formats yourself (eg linked to one or more drivers), and then using the ServiceLoader or DriverManager, discover the available drivers and use that to determine which URL formats you can use.
Be aware that JDBC allows multiple drivers to use the same JDBC URL format (the first driver to successfully connect 'wins'), and a single driver can have more than one JDBC URL format.
To discover the JDBC drivers on the classpath, you can use
ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);
for (Driver driver : loadedDrivers) {
// do something with Driver
}
Be aware that using for-each might not be the best solution. Explicitly using the iterator might be better as then you can explicitly handle the ServiceConfigurationError thrown if a specific driver fails to load.
Alternatively, you can use
Enumeration<Driver> drivers = DriverManager.getDrivers();
And let DriverManager take care of discovering the drivers.
Maybe you can use a framework, which abstracts the layer of data access i.e. all the talking to the database?
I could recommend you Spring Data JDBC. https://spring.io/projects/spring-data-jdbc
But there are more frameworks that you could find as OR-Mapper which could help you.

Use SQL driver from buildpack to deploy app with multiple datasources on Pivotal Cloud Foundry

I have a war application that I wish to deploy and configure with multiple mysql services. When the application is bound to one mysql service, PCF automatically configures the datasource using the SQL driver downloaded by the java-buildpack. I want to avoid having to package the driver within the war file. Is there a way to use the driver from the buildpack without autoconfiguration?
The java-buildpack documentation on GitHub seems to suggest that if the service is named or tagged with "mysql" then the driver will be downloaded and placed on the classpath:
A user-provided MariaDB or MySQL service must have a name or tag with mariadb or mysql in it so that the MariaDB JDBC Framework will automatically download the JDBC driver JAR and place it on the classpath.
However both of my services are tagged with "mysql":
"name": "database1",
"tags": [
"mysql",
"relational"
]
But when the application is started return the error:
Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
And when staging the app, the JDBC driver is not downloaded.
The documentation link you referenced also lists this requirement for the functionality to execute:
Existence of a single bound MariaDB or MySQL service and no provided MariaDB or MySQL JDBC JAR.
The key word there is single. That is why it's not working when you have two services bound.
I'm not sure there's much you can do. It'll work when there's only one MySQL service bound, but not more than one. That's the defined behavior.
Options going forward: file a Github issue and ask to support your use case, package the JDBC driver with your app.

Derby EmbeddedDriver working without Class.forName

The documentation tells us to load JDBC driver like so
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
https://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
But it works fine without and getting the connection straight away
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
Why is that?
Version from the log: Booting Derby version The Apache Software Foundation - Apache Derby - 10.13.1.1 - (1765088)
EDIT:
Actually it is needed if you shut down the Derby engine and want to open it again in the same JWM process (I do this all the time in my integration tests)
After shut down
DriverManager.getConnection("jdbc:derby:;shutdown=true");
You should reopen like this
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
connection = DriverManager.getConnection("jdbc:derby:" + pathDerby + ";create=true");
From official documentation:
The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:
my.sql.Driver
Applications no longer need to explicitly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.

Firebird and Hibernate - How do you specify a DB role?

I'm working in a new project to convert our Delphi + Firebird system to Java 8 / JavaFX / JPA (Hibernate) and Firebird. We are using the latest version of Jaybird and connecting to Firebird 1.5, Firebird 3.0 and InterBase XE3 databases. I have not found any documentation on connecting to the DB specifying a DB role. Is there a way to do this?
To specify the user role, you need to specify the roleName property in the connection string. See also Extended connection properties in Jaybird JDBC Driver Java Programmer's Manual.
Example of a connection string:
jdbc:firebirdsql://localhost/database?charSet=UTF-8&roleName=myrole

mapping database link(drda) tables to entites in jpa

I'm using a oracle thin driver to connect to my database.My database links to another db(DB2) with drda specification.My problem is that I can only view the local tables of my database and map them using jpa but I select from drda in sqldeveloper and it works so the problem is definitely with my application development.What do you think is missing?
my application characteristics are as follows:
IDE: MyEclipse 6.5
Struts
Spring 2.5/JPA
Oracle 10g
Tomcat 6.x
Do I need to specify a jta-data-source? Right now I'm not using a data source?
please help me
Just make sure you have followed these steps given by Oracle.

Categories