You know, Apache Derby is a lightweight, portable database engine written purely in Java. Java DB is a just an Oracle’s distribution of Derby in their JDK. However, since Java 9, JavaDB is removed from JDK installation.
Following steps are helpful for quickly get started with Derby, from downloading its JDBC driver to write code for making connections.
1. Downloading Derby JDBC driver library
Download the latest version of Derby here (as of this writing, the latest release is 10.15.1.3).
If you are using JDK 1.7, then Derby is already included in JDK installation under the name Java DB folder(java db folder exist in jdk folder and jdk folder exist in java folder and java folder exist in PROGRAM FILE and PROGRAM FILE folder exist in C: Drive)
you have to place appropriate jar file to the classpath:
derby.jar: for embedded driver.
derbyclient.jar: for network client driver.
This is the code for connecting java to JAVA DB database through JDBC.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class JavaDbConnection {
public static void main(String[] args) {
try {
String host = "jdbc:derby://localhost/csdt;";
String user = "csdt";
String password = "csdt";
Connection con = DriverManager.getConnection(host, user, password);
if (con != null) {
System.out.println("Successful Connected with database.");
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
}