How to use SQLDeveloper to connect to embedded Derby database

前端 未结 4 1815
悲哀的现实
悲哀的现实 2021-01-06 06:45

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

相关标签:
4条回答
  • 2021-01-06 07:17

    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.

    0 讨论(0)
  • 2021-01-06 07:17

    After many "bad URL format" and then some "null pointer exceptions" I finally succeeded to get this connection working! In my context not to an embedded DERBY Database, but to Derby launched as a network server. Here is the checklist:

    • Using SQL developer version 20.x (earlier may do - not checked) with a JDK 8 (above 171 is required by SQL developer). The later contains javaDB that is historically the Apache DERBY 10 database.

    • DERBY is started and listens to port 1527 (its default). Permissions must indeed allow localhost and/or remote connections according to your context. I strongly advise you to have your database ready, and then check connectivity with e.g. the native Derby command line tool 'ij'. For instance, at the ij prompt:

    ij> connect 'jdbc:derby://localhost:1527/MyDB;user=MYUSER;password=abcd';
    
    • ensure you add the Derby JDBC driver to SQL Developer > Tools > Preferences > Database > Third Party JDBC Drivers. Browse and add yourJDKpath\db\lib\derbyclient.jar; this single jar is sufficient.

    • Create a new connection, just for having the entry created in the connection config file that we will have to manually edit. Ensure you give it the name you want, with the proper user and password. Fill-in any data for the other fields and save your connection. It can't work yet.

    • Exit SQL developer and edit manually the connection meta data. In recent SQL developer versions, this file is in JSON, previous versions are XML, the attribute names are identical in both cases. The path is like:

    C:\Users\YourNAME\AppData\Roaming\SQL Developer\system20.2.0.175.1842\o.jdeveloper.db.connection\connections.json
    
    • Open the file and identify the connection you just created. Edit it to get something like:

           {
           "info": {
               "role": "",
               "SavePassword": "true",
               "OracleConnectionType": "BASIC",
               "RaptorConnectionType": "Microsoft SQL Server",
               "customUrl": "jdbc:derby://localhost:1527/MyDB",
               "NoPasswordConnection": "TRUE",
               "password": "123456789PLVEC4wxu80ijhx5ALU4ZpRgo123456789=",
               "hostname": "localhost",
               "port": "1527",
               "subtype": "SQLServer",
               "ConnName": "DerbyDB",
               "driver": "org.apache.derby.jdbc.ClientDriver",
               "IS_PROXY": "false",
               "OS_AUTHENTICATION": "false",
               "KERBEROS_AUTHENTICATION": "false",
               "user": "MYUSER"
           },
           "name": "local DERBY",
           "type": "jdbc"
       }
      
    • Yes, you may have noted the references to "Microsoft SQL Server" as RaptorConnectionType and "SQLServer" as subtype. This is the magic trick. Of course, the client driver classpath is critical too, which is "org.apache.derby.jdbc.ClientDriver" for the Derby network mode client, as is the connectionUrl.

    • Launch SQL Developer and open the connection that will appear under "SQLServer Connections"

    0 讨论(0)
  • 2021-01-06 07:36

    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

    0 讨论(0)
  • 2021-01-06 07:40

    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.

    0 讨论(0)
提交回复
热议问题