My version is JDK-15.0.1
Directory of C:\Program Files\Java
2020-11-17 07:27 PM <DIR> .
2020-11-17 07:27 PM <DIR> ..
2020-11-17 07:27 PM <DIR> jdk-15.0.1
0 File(s) 0 bytes
3 Dir(s) 620,601,839,616 bytes free
C:\Program Files\Java>cd\Program Files\Java\jdk-15.0.1
C:\Program Files\Java\jdk-15.0.1>dir
Volume in drive C is Acer
Volume Serial Number is F8C5-C787
Directory of C:\Program Files\Java\jdk-15.0.1
2020-11-17 07:27 PM <DIR> .
2020-11-17 07:27 PM <DIR> ..
2020-11-17 07:27 PM <DIR> bin
2020-11-17 07:27 PM <DIR> conf
2020-09-15 02:08 PM 3,244 COPYRIGHT
2020-11-17 07:27 PM <DIR> include
2020-11-17 07:27 PM <DIR> jmods
2020-11-17 07:27 PM <DIR> legal
2020-11-17 07:27 PM <DIR> lib
2020-11-17 07:27 PM 1,231 release
2 File(s) 4,475 bytes
8 Dir(s) 620,593,610,752 bytes free
C:\Program Files\Java\jdk-15.0.1>
According to the book I am to do the following;
3. Locate the line
@rem set DERBY_INSTALL =
and change it to
@set DERBY_INSTALL=%JAVA_HOME%\db
What the purpose is, I do not know. I am just learning and trying to follow along step by step.
I tried to run the sample code that was provided,
package books;
// Fig. 24.23: DisplayAuthors.java
// Displaying the contents of the Authors table.
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class DisplayAuthors {
public static void main(String args[]) {
//final String DATABASE_URL = "jdbc:derby:books";
final String DATABASE_URL = "books";
final String SELECT_QUERY =
"SELECT authorID, firstName, lastName FROM authors";
// use try-with-resources to connect to and query the database
try (
Connection connection = DriverManager.getConnection(
DATABASE_URL, "deitel", "deitel");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SELECT_QUERY)) {
// get ResultSet's meta data
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.printf("Authors Table of Books Database:%n%n");
// display the names of the columns in the ResultSet
for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-8s\t", metaData.getColumnName(i));
}
System.out.println();
// display query results
while (resultSet.next()) {
for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-8s\t", resultSet.getObject(i));
}
System.out.println();
}
}
catch (SQLException sqlException) {
sqlException.printStackTrace();
}
}
}
/**************************************************************************
* (C) Copyright 1992-2018 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
*************************************************************************/
but I get the following error
run:
java.sql.SQLException: No suitable driver found for books
at java.sql/java.sql.DriverManager.getConnection(DriverManager .java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager .java:228)
at books.DisplayAuthors.main(DisplayAuthors.java:20)
BUILD SUCCESSFUL (total time: 7 seconds)
Also, just in case you need to know, I am running this on NetBeans IDE 12.4