This blog post is an errata item for my Java Fundamentals course, and will also apply for the other Virtual Pair Programmers courses where we use the db-derby database.
I discovered while recording the upcoming Groovy course that there has been a security change in the most recent release of Java (1.7.0.51) that has meant that the default configuration for db-derby no longer works. Running db-derby with the startNetworkServer command will result in an error message which says somewhere early on in the error message:
access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
The easiest and quickest way to overcome this seems to be to run the database on a higher port number, such as 50000 - to do this, instead of running the startNetworkServer command, run the following instead to start the db-derby database:
NetworkServerControl -p 50000 start
In your code, you'll need to change the connection strings to incorporate the new port number, so that the line of code which creates the connection includes the port number - it should look like this:
conn = DriverManager.getConnection("jdbc:derby://localhost:50000/library");
This should overcome the error - if you find you have any further unexpected errors that you can't resolve however, do get in contact via the Virtual Pair Programmers contact us page!
Doing this also requires you to add the port number when accessing the database from the command line:
ReplyDeleteFAIL:
ij> connect 'jdbc:derby://localhost/MyDatabase;create=true';
ERROR 08001: java.net.ConnectException : Error connecting to server localhost on
port 1527 with message Connection refused: connect.
SUCCESS:
ij> connect 'jdbc:derby://localhost:50000/MyDatabase;create=true';
I followed the 2 comment threads above and It worked fine. However the Customer, lianes and material tables did not appear at the end of the list. Any idea how to sort this out?
ReplyDeleteIs okay, problem solved
ReplyDeleteThank you this helped me as well.
ReplyDeleteThanks Matt. It works fine now.
ReplyDeleteBefore this I edited the Java Policy by adding:
permission java.net.SocketPermission "localhost:1527", "listen";
But still it didn't work.