execute() method of the Statement object is used to retrieve data from a table. This sample code first makes a JDBC connection to the database and then retrieves all the records of the table and stores it. It uses ResultSet object to store the data. Then content of the ResultSet is printed to the console.

 import java.sql.*;

public class InsertValue {

        public static void main(String[] args) {
                 String url = " jdbc:odbc:dumy ";
    
     try {
             
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:dumy"; "sa", "");
            Statement stmt = con.createStatement();
            ResultSet reset = stmt.execute("select ename,job from emp");

            //Print the data to the console
            while(reset.next()){
                      System.out.println(reset.getString(1));
                      System.out.println(reset.getString(2));
            }  
    
    catch( Exception e ) {
      e.printStackTrace();        
    }
  }
}