I want to create a desctop application with an embedded data base. Data base is JavaDB(Derby). I have connected a jar file derby.jar to my project. The problem is I don’t understand how to register a driver to use this data base. It is said that I should use
Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”)
But what if that was another data base and its driver was not in a java standart package?
As you can see I’m confused with this. I want to know, how to use my connected derby.jar, how to work with its jdbc driver and how to create tables in a specified directory.
Please, give as detailed answer, as you can. (I’m a dummy in this =)) )
You use a statement like:
to load and register the JDBC driver class for Derby, so that the JDBC
java.sql.DriverManagercan find the driver when you want to connect to the database. If you want to connect to a different database or use a different driver implementation, you’ll have to change the name for the driver you’re using. Ofcourse you can put the information in a configuration file instead of hard-coding it in your program, so that you can change the driver without re-compiling your program.For example, put the necessary information in a configuration file
database.properties:Then load those settings in your program and use them to open a database connection:
See the Apache Derby Tutorial and Sun’s JDBC Tutorial.