I am a newbie at JAVA and SQL.
In one exercise, I need to read data from a sample SQL table in NetBeans.
In "services", I started the JAVA DB server. All good. The following message appeared:
Mon Dec 16 21:40:36 EST 2013 : Security manager installed using the Basic server security policy.
Mon Dec 16 21:40:37 EST 2013 : Apache Derby Network Server - 10.8.3.0 - (1405108) started and ready to accept connections on port 1527
But when I run this program (below), the following error occurs:
SQL Error: java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/sample 0 08001
Here are the codes.. how can I make sure the right driver is found?
import java.sql.*;
public class TableReporter {
public static void main(String[] args) {
String data = "jdbc:derby://localhost:1527/sample";
try (
Connection conn = DriverManager.getConnection(
data, "app", "APP");
Statement st = conn.createStatement()) {
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());
}
}
}