How to use SQLDeveloper to connect to embedded Derby database

我与影子孤独终老i 提交于 2019-12-19 04:16:05

问题


I have a project using derby and JPA. I can connect to the database fine within my application. I would like to connect to the embedded database with SQL Developer so I can easily browse/query the data in the database.

Here is the derby dependency I'm using:

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>10.7.1.1</version>
</dependency>

Here is the the connection info I'm using for JPA:

<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:fs-hash-database;create=true"/>

Using SQL Developer 3.2.09 I tried to add the driver in Tools > Preferences > Database > Third Party JDBC Drivers with the following entry:

C:\Users\axiopisty\.m2\repository\org\apache\derby\derby\10.7.1.1\derby-10.7.1.1.jar

But when I try to create a new connection, SQL Developer still only shows me the tabs for Oracle and Access. I can't get the JDBC tab for the 3rd party driver.

I think the problem is that the jar that I am adding as the 3rd party driver is the entire derby jar, not just the driver. Yet the driver is contained in the jar.

Does anyone know how to configure SQL Developer to use the org.apache.derby.jdbc.EmbeddedDriver contained within derby-10.7.1.1.jar?


回答1:


Oracle SQL Developer can be manually configured to work with Derby using the drivers that come with the JDK as of Java 8.

Step 1: In Oracle SQL Developer, include Derby related libraries.

Oracle SQL Developer -> Tools -> Preferences -> Databases -> Third Party JDBC Drivers. I simply [Add Entry...] all libraries under C:\Program Files\Java\jdk1.8.0_92\db\lib

Step 2: Manually edit connections.xml

Edit C:\Users\USERNAME\AppData\Roaming\SQL Developer\system4.1.2.20.64\o.jdeveloper.db.connection.12.2.1.0.42.151001.541\connections.xml

In this example I am using embedded Derby driver.

<Reference name="DerbyConn" className="oracle.jdeveloper.db.adapter.DatabaseProvider" xmlns="">
  <Factory className="oracle.jdevimpl.db.adapter.DatabaseProviderFactory1212"/>
  <RefAddresses>
     <StringRefAddr addrType="OracleConnectionType">
        <Contents>BASIC</Contents>
     </StringRefAddr>
     <StringRefAddr addrType="RaptorConnectionType">
        <Contents>Microsoft SQL Server</Contents>
     </StringRefAddr>
     <StringRefAddr addrType="customUrl">
        <Contents>jdbc:derby:firstdb;create=true</Contents>
     </StringRefAddr>
     <StringRefAddr addrType="driver">
        <Contents>org.apache.derby.jdbc.EmbeddedDriver</Contents>
     </StringRefAddr>
     <StringRefAddr addrType="subtype">
        <Contents>SQLServer</Contents>
     </StringRefAddr>
     <StringRefAddr addrType="ConnName">
        <Contents>DerbyDB</Contents>
     </StringRefAddr>
  </RefAddresses>

Note:
1. The XML setting can be as plain as shown above.
2. customUrl is jdbc:derby:firstdb;create=true. This will initialize firstdb schema in C:\sqldeveloper\bin\firstdb. You can use jdbc:derby:D:\\Project\\derbydb\\firstdb to initialize schema to an absolute location.




回答2:


SQL Developer does not support Apache Derby. It only supports a very limited (and fixed) set of DBMS as documented on the WebSite:

  • Oracle (obviously)
  • MySQL (obviously)
  • SQL Server
  • DB2
  • MS Access
  • Sybase
  • Teradata

(All third party DBMS are listed as "read-only" on the website - whatever that means)

You will need a "real" general purpose JDBC client to use it against Derby like Squirrel, DbVisualizer or SQL Workbench/J.




回答3:


I was able to get this to work on sql developer 4.0.2.15 using the network driver by adding the driver files to the classpath and then editing the connections.xml file in the directory AppData\Roaming\SQL Developer\system4.0.2.15.21\o.jdeveloper.db.connection.12.1.3.2.41.140418.1111

I did this by copying an sql server connection but it seems to work happily thinking it is an sql server database.

I added the following to the file :

     <Reference name="DATABASENAME" className="oracle.jdeveloper.db.adapter.DatabaseProvider" xmlns=""\>
      <Factory className="oracle.jdevimpl.db.adapter.DatabaseProviderFactory1212"/>
      <RefAddresses>
         <StringRefAddr addrType="port">
            <Contents>1527/DATABASENAME</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="user">
            <Contents>USERNAME</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="NoPasswordConnection">
            <Contents>TRUE</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="subtype">
            <Contents>SQLServer</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="RaptorConnectionType">
            <Contents>Microsoft SQL Server</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="ConnName">
            <Contents>DATABASENAME</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="hostname">
            <Contents>HOSTNAME</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="customUrl">
            <Contents>JDBCURL</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="SavePassword">
            <Contents>false</Contents>
         </StringRefAddr>
         <StringRefAddr addrType="driver">
            <Contents>org.apache.derby.jdbc.ClientDriver</Contents>
         </StringRefAddr>
      </RefAddresses>
   </Reference>

You will have to configure it with the appropriate values for DATABASENAME, USERNAME, HOSTNAME and JDBCURL for your database.

I hope this helps



来源:https://stackoverflow.com/questions/12232258/how-to-use-sqldeveloper-to-connect-to-embedded-derby-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!