I'm trying to set up a Java DB Database for a programming class. I'm following the steps in the Deitel and Deitel textbook:
I have JDK11.8.0_112 installed. I'm running Windows 10.
My install is at C:\Program Files\Java\jdk1.8.0_112 I have the JAVA_HOME var set as C:\Program Files\Java\jdk1.8.0_112
The textbook says to go the install location db\bin and edit the setEmbeddedCP.bat file from @rem set DERBY_INSTALL= to @SET DERBY_INSTALL=%JAVA_HOME%\db
Then open a command prompt and go to the directory of that file and run it, which I've done, this is the result:
The book has some source code to create the tables. I copied and pasted into my own project, C:\Users\hulbe\OneDrive\Documents\NetBeansProjects\DisplayAuthors\build\classes\displayauthors.
The book then states to use the command line and change directories to the folder with chapters examples, which are now in my own project.
Next, type "%JAVA_HOME%\db\bin\ij" into the command line.
Then, connect 'jdbc:derby:newbooks;create=true;user=xxx;password=xxx'; I've got the DB and the tables to create (I think). But when I run the code I get "java.sql.SQLException: No suitable driver found for jdbc:derby:newbooks"
I'm really at my wits end here. I've spent two days now trying to set up clean installs and walking through exactly like how the books is set up.
Here's the code: `try ( Connection connection = DriverManager.getConnection( DATABASE_URL, "deitel", "deitel");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_QUERY)) {
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.printf("Authors Table of Books Database: %n%n");
for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-8s\t", resultSet.getObject(i));
}
}
catch (SQLException sqlException) {
sqlException .printStackTrace();
}`
I know this is long and I'm sure it falls under already been asked, but nothing I've seen is helping me figure this out.
Anybody know what I'm doing wrong?
EDIT: The problem was that I had to extract the derby.jar files and add them manually, thank you Marco Tizzano.
Now, however, I am getting this error: java.sql.SQLException: Database 'books' not found. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.(Unknown Source) at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source) at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at displayauthors.DisplayAuthors.main(DisplayAuthors.java:24) Caused by: ERROR XJ004: Database 'books' not found.
EDIT 2: I think I was creating the DB in the wrong directory, I reran it in the correct directory, ProjectName->src->proejctname. The command prompt displayed all the right SQL stuff, table creation and column names and such and then ran the inserts. This also created a folder in that directory with the db name, but still the DB not found error.