Hi Amy,

It's hard to tell what's going on without seeing the full stack trace. I'm afraid that I don't have a lot of experience with RowSets. The error message seems to indicate that the Derby embedded driver is not loaded into the RowSetFactory's class loader.

I have a couple questions about your experiment, though:

1) Why is your call to RowSet.setUrl() inventing its own url rather than using the url parameter of the method? What is the point of printing the url on the next line, given that it is not necessarily the url which was set inside the RowSet?

2) Why is a null ClassLoader passed to RowSetProvider.newFactory()?

3) What happens if, instead of a null ClassLoader, you pass in conn.getClass().getClassLoader()?

Thanks,
-Rick

On 12/3/17 7:01 AM, Amy E. Brown wrote:
Good morning all,

New to Derby and JDBCRowsets, not so new to JDBC itself.

I'm working in IntelliJ Idea and have added derby.jar, derby-tools.jar, and derby-client.jar as libraries.

I've been returning result sets from my test database all morning without an issue, so connections and the data in the table aren't a problem.

However, I get a "no suitable driver found" exception when I run the execute method of a JDBCRowSet object.

Here's the relevant code with some values hard-coded. As you can see, the first thing I do in the try block is return a result set, and that works fine.



   public void JdbcRowSetDemo(String url, String userName, String password, String rowSetQuery, int rowNumber, Connection conn, String resultSetQuery) {

        RowSetFactory rsf = null;
        JdbcRowSet rowSet = null;

        try {
            System.out.println("We are at the first line of the demo class.");
            this.getResultSet(conn, resultSetQuery);
            rsf = RowSetProvider.newFactory("com.sun.rowset.RowSetFactoryImpl", null);
            rowSet = rsf.createJdbcRowSet();
rowSet.setUrl("jdbc:derby:c:/Users/user/JDBCTutorial/testdb");
            System.out.println(url);
            rowSet.setUsername("");
            rowSet.setPassword("");
            rowSet.setCommand("SELECT * FROM COFFEES");
            rowSet.execute();
            System.out.println("We just executed the rowset query.");

....

Here's the method call to get the result set.

    private void getResultSet(Connection conn, String query) {
        Statement stmt = null;
        try {
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            System.out.println("you just created a statement");
            ResultSet rs = stmt.executeQuery(query);

            while (rs.next()) {
                String coffeeName = rs.getString("COF_NAME");
                int supplierID = rs.getInt("SUP_ID");
                float price = rs.getFloat("PRICE");
                int sales = rs.getInt("SALES");
                int total = rs.getInt("TOTAL");
                System.out.println("Results of new query:" + coffeeName + ", " + supplierID + ", " + price +
                        ", " + sales + ", " + total);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }


Reply via email to