How to use SQLDeveloper to connect to embedded Derby database

喜你入骨 提交于 2019-11-30 23:06:03
oraclesoon

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.

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.

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

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