I am fairly new to Java, so I bought a book to learn from. Everything went swimmingly until I got to the chapter on SQL. I am working in NetBeans with the sample database, but I can't get the database to connect with the program.
Here's the code I faithfully copied from the book:
import java.sql.*;
public class SysTableReporter {
public static void main(String[] arguments) {
String data = "jdbc:derby://localhost:1527/sample";
try (
Connection conn = DriverManager.getConnection(
data, "app", "APP");
Statement st = conn.createStatement()) {
System.out.println("TABLEID:\t" );
Class.forName("org.apache.derby.jdbc.ClientDriver");
ResultSet rec = st.executeQuery(
"select * " +
"from SYS.SYSTABLES " +
"order by TABLENAME");
while(rec.next()) {
System.out.println("TABLEID:\t" + rec.getString(1));
System.out.println("TABLENAME:\t" + rec.getString(2));
System.out.println("TABLETYPE:\t" + rec.getString(3));
System.out.println("SCHEMAID:\t" + rec.getString(4));
System.out.println();
}
st.close();
} catch (SQLException s) {
System.out.println("SQL Error: " + s.toString() + " "
+ s.getErrorCode() + " " + s.getSQLState());
} catch (Exception e) {
System.out.println("Error: " + e.toString() + e.getMessage());
}
}
}
Here's what my Services Panel looks like:
Here's my output:
SQL Error: java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/sample 0 08001
At first I figured I just had some typo, but looking over it carefully I can't find it. I tried installing a new JDBC driver, but that didn't seem to help either. I'm running a Windows 8 laptop, and I have the telnet client turned on. My best guess at this point is that I somehow missed a step in the initial setup, but I can't find it to go back and fix it. Any help would be great.