I need to do some simple experiments using JDBC in Java, and thought that running up a derby database should be a simple route to that.
I have installed derby, and used the "ij" tool to create a table and get some data into it. I can read that data back using ij too.
However, when I try to connect to this using actual Java code, things go badly. This is one of those situations where I've tried several things, and each fails differently, so I hope you'll all forgive this getting a bit fuzzy edged. But these are the key points of what I've tried/failed so far.
- This is a maven project, and there is a dependency in place for artifactId "derbyclient" version 10.15.2.0
- The ij tool connects to my database (which is on the localhost, but not "embedded") successfully using the url jdbc:derby:firstdb
- The docs that I found (finally!) that talked somewhat about non-embedded mode said the driver should be org.apache.derby.jdbc.ClientDriver, but that class is not found. I found notes in the gihub for the liquibase project that said this is now org.apache.derby.client.ClientAutoloadedDriver. Using that classname, doesn't throw the class not found error, which seems like a step forward.
- Although the above driver loads, the jdbc url shown above fails with "No suitable driver for jdbc:derby:firstdb"
- I found other notes that suggested the url should be of the form jdbc:derby://localhost/firstdb however, that says "The connection was refused because the database firstdb was not found". I've tried a couple of variations of naming the db, but they resulted in "no suitable driver" again.
- At the prompting of g00se in the comments, I went looking for the ClientDriver that I noted above was not found. I discovered this in the main derby distribution in a file derbytools.jar, but not in any of the jars that maven loaded. I tried executing this using a hand-built command line so I could put the derbytools on the classpath. This allowed that to be loaded as a driver, but it connects to an in-JVM database (which works, I can do stuff with this). However, it does not connect to the running network server which is what I want to achieve. When I try to force its hand by using a URL of the form jdbc:derby://localhost:1527/firstdb, it again fails telling me the database was not found.
- I've also discovered that there seems to be no need to do the "Class.forName" thing anyway, nor to be concerned about having ClientDriver on the classpath. Somehow a driver is loaded and available when I do DriverManager.getConnection. However, with the URLs I've tried, I have utterly failed to make it connect to the network server, it always connects to an in-JVM server (which works, but isn't where I want to connect.)
Can anyone tell me how to get this to work?