Search code examples
javasqldatabaserecordset

How to set the "RecordSet", using SQL, to connect to a database


I've been using a tutorial to learn how to create and connect to a database using Java. Link to the tutorial.

In the tutorial it says I need to set the "RecordSet" type to TYPE_SCROLL_SENSITIVE (or whatever type you want to use.)

When I try to call the RecordSet class, I get an error saying:

cannot find symbol. symbol: variable RecordSet. location: class DataBase

I've tried fixing imports (does nothing), and I've also tried importing the entire SQL package. I think the RecordSet class may have been changed, or it is not in SQL.

Here's my code:

package database;

import java.sql.*;

public class DataBase {

    public static void main(String[] args) {

    try{
        String host = "jdbc:derby://localhost:1527/Employees";
        String SQL = "SELECT * FROM Workers";
        String uName = "nbur4556";
        String uPass = "95086733";

        Connection con = DriverManager.getConnection(host, uName, uPass);
        Statement stmt = con.createStatement(RecordSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = stmt.executeQuery(SQL);
    }catch(SQLException err){
        System.out.println(err.getMessage());
    }

}//End Method


}//End Class

So my question is, does anyone know how to set the "RecordSet" class so I can continue setting up the database?


Solution

  • It is ResultSet and not RecordSet

    Change

      Statement stmt = con.createStatement(RecordSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    

    TO

      Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);