2

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)
6
  • You use a function not implemented in your code. You should find another way to do what you do. Can you add the stracktrace in your question ? Commented Dec 4, 2016 at 18:20
  • how do I get the stacktrace? I am using the Netbeans Ide Commented Dec 4, 2016 at 18:21
  • Fast answer : you may do e.printStackTrace() in your catch block. A logger is better. Commented Dec 4, 2016 at 18:22
  • I added the stack trace to the question Commented Dec 4, 2016 at 19:01
  • Is their any other way to retrieve the whole table in a ResultSet object other then (select * from people;)? Commented Dec 4, 2016 at 19:02

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.