javajdbc

java sqlite - Error: function not yet implemented for SQLite


I created the following class in java to make using SQLite easier when I code.

import java.sql.*;

public class Dbm {
//We want to use the connection throughout the whole class so it is
//provided as a class level private variable
private Connection c = null;
//This constructor opens or creates the database provided by the argument
// NameOfDatabase
public Dbm(String NameOfDatabase) {
 
try {
  // Database is checked for in project folder, if doesn't exist then creates database
  c = DriverManager.getConnection("jdbc:sqlite:" + NameOfDatabase);
} catch ( Exception e ) {
  System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  System.exit(0);
}
System.out.println("Opened database successfully");
}

public void CloseDB() {
try {
c.close();
System.out.println("Closed database successfully");
}
catch (Exception e) {
System.out.println("Failed to close database due to error: " + e.getMessage());
}
}

public void ExecuteNoReturnQuery(String SqlCommand) {
// creates a statement to execute the query
try {
    Statement stmt = null;
    stmt = c.createStatement();
    stmt.executeUpdate(SqlCommand);
    stmt.close();
    System.out.println("SQL query executed successfully");
} catch (Exception e) {
   System.out.println("Failed to execute query due to error: " +     e.getMessage());
}
}

// this method returns a ResultSet for a query which can be iterated over
public ResultSet ExecuteSqlQueryWithReturn(String SqlCommand) {
try {
    
Statement stmt = null;
stmt = c.createStatement();

ResultSet rs = stmt.executeQuery(SqlCommand);
return rs;
} catch (Exception e) {
System.out.println("An error has occurred while executing this query" + e.getMessage());
}
return null;
}
}

Here is the main code in the program

import java.sql.*;

public class InstaText {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
 Dbm db = new Dbm("people.db");
 ResultSet rs = db.ExecuteSqlQueryWithReturn("select * from people;");
try {
   String name = "";
   int age = 0;
   String address = "";

 while (rs.isLast() == false) {
 name = rs.getString("name");
 age = rs.getInt("age");
 address = rs.getString("address");
         System.out.println("Name is " + name +" age is " + age + " Address is " + address);
         rs.next();
 }
} catch (Exception e ) {
System.out.println("Error: " + e.getMessage());
}
      db.CloseDB();
   }
 }

But when I execute it I get the following output:

 Opened database successfully
 Error: function not yet implemented for SQLite
 Closed database successfully

So how do I solve the error:

Error: function not yet implemented for SQLite

I am running the NetBeans Ide with the latest JDBC on mac os sierra.

Edit: here is the output after adding e.printstacktrace(); in the catch block:

Opened database successfully
Error: function not yet implemented for SQLite
java.sql.SQLException: function not yet implemented for SQLite
Closed database successfully

at org.sqlite.jdbc3.JDBC3ResultSet.isLast(JDBC3ResultSet.java:155)
at instatext.InstaText.main(InstaText.java:24)

Solution

  • The problem is not your select query but the isLast() method you are using on the ResultSet instance to retrieve the result.
    Try the next() method, it should work :

    while (rs.next()){
     name = rs.getString("name");
     age = rs.getInt("age");
     address = rs.getString("address");
             System.out.println("Name is " + name +" age is " + age + " Address is " + address);
             rs.next();
     }
    

    You can read here : https://github.com/bonitasoft/bonita-connector-database/issues/1 that with SQLLite, you may have some limitations with the isLast() method :

    According to JDBC documentation (http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html) calls to isLast() and first() methods are forbidden if the result set type is TYPE_FORWARD_ONLY (e.g SQLite).