Reputation: 61
I've been searching for a little while and can't find where Eclipse Neon stores my database files which I create with Derby and Java. Older documentation shows an "Apache Derby" option in the context menu, but that doesn't appear for me.
In the older documentation, I also saw something about an IJ SQL interface for Derby. I would also like to know if this IJ interface is still available with Eclipse Neon, and how to open it.
Thanks!
Upvotes: 0
Views: 847
Reputation: 147
I don't think that eclipse can store the Database, but you can write your Java code in eclipse that creates a Derby database, tables and so on, as well as you can use with the ij-tool of Derby database for create a database.
Two ways how to create a Derby database and where the database that created saved.
** By default, automatically database saved where you run the startNetworkServer.bat.
Sample example for creating a database from java code (eclipse):
public class CreateDatabase {
public static void main(String[] args) {
String driverName = "org.apache.derby.jdbc.ClientDriver";
// Creating all tables for database DDL for TABLES
try {
Class.forName(driverName);
System.out.println("driver loaded");
String url = "jdbc:derby://localhost:1527/MyDB;create=true";
// ARM technology
try (Connection con = DriverManager.getConnection(url);) {
// get a connection to a specific database (inside ARM)
System.out.println("connected to: " + con);
Statement stmt = con.createStatement();
// create a Statement for all tables
String companyTable = "CREATE TABLE Company"
+ "("
+ "COMPANY_ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),"
+ "COMPANY_NAME VARCHAR(20),"
+ "COMPANY_PASSWORD VARCHAR(16),"
+ "EMAIL VARCHAR(30),"
+ "CONSTRAINT PRIME_COMPANY_ID PRIMARY KEY (COMPANY_ID)"
+ ")";
stmt.executeUpdate(companyTable);
System.out.println("success: " + companyTable);
String customerTable = "CREATE TABLE Customer"
+ "("
+ "CUSTOMER_ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),"
+ "CUSTOMER_NAME VARCHAR(25),"
+ "CUSTOMER_PASSWORD VARCHAR(16),"
+ "CONSTRAINT PRIME_CUSTOMER_ID PRIMARY KEY (CUSTOMER_ID)"
+ ")";
stmt.executeUpdate(customerTable);
System.out.println("success: " + customerTable);
System.out.println("The database MyDB created successfully");
}
System.out.println("connection closed");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
Sample example for creating a database from ij-tool of (Derby):
go to bin directory of Derby database and -
1. run the startNetworkServer.bat
2. run the ij.bat
3. in ij-tool write connect 'jdbc:derby://localhost:1527/MyDB;create=true';
in 3rd steps we create a database that named MyDB and it appears in this - bin directory.
After the database created you can create the tables...
https://db.apache.org/derby/docs/10.7/ref/rrefsqlj24513.html#rrefsqlj24513
Upvotes: 1