#Help me fix SQLite error.

1 messages · Page 1 of 1 (latest)

dark patrol
#

So im making a minecraft plugin for a server and i use SQLite for the data base and with it i also use ORMLite for esier use of SQLite.

The .db file is created and no errors happen, but when i excecute the function that should in theory change the BuildMode value from False to True, it shows this error when it gets to the if statement that checks the data base and sees if the current BuildMode value is set to True or False. (Basicly it is a toggle)

Im new to Databases and maybe tought someone that might know whats wrong here.

tawdry cryptBOT
#

<@&987246652869971988> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

are thrown when the database is accessed. However, when trying to execute a query or perform any operation on the database, you encounter an SQLite error. To fix this issue, you can follow these steps:

  1. Check the SQLite version: Ensure that you are using a compatible version of SQLite with ORMLite. Sometimes, using an outdated or incompatible version can cause errors. Make sure both ORMLite and SQLite are up to date.

  2. Verify the database file path: Double-check that the path to your .db file is correct and accessible by your plugin. Ensure that the file is located in the expected directory and that it has proper read/write permissions.

  3. Confirm table and column names: Make sure that the table and column names used in your queries match exactly with the ones defined in your database schema. Any mismatch can result in SQLite errors.

#
  1. Handle exceptions: Wrap your database operations with try-catch blocks to catch any exceptions thrown by SQLite or ORMLite. This will help you identify specific errors and provide more detailed error messages for troubleshooting.

  2. Enable verbose logging: Enable verbose logging for SQLite to get more information about the error. You can do this by setting PRAGMA verbose = 1; before executing any queries or operations on the database.

  3. Test with simple queries: Start with simple queries like SELECT statements on a single table to ensure basic functionality is working correctly before moving on to more complex operations.

  4. Consult documentation and forums: Check the official documentation for ORMLite and SQLite for any specific troubleshooting steps related to your error message or scenario. Additionally, search online forums or communities where other developers may have encountered similar issues and found solutions.

  5. Consider alternative libraries: If you continue facing issues with ORMLite and SQLite integration, you might consider using alternative libraries for interacting with SQLite databases in Java, such as Room Persistence Library or SQLDelight.

By following these steps, you should be able to identify and fix the SQLite error in your Minecraft plugin.

solid wolf
#

What do you have so far?

dark patrol
#

Currently it creates the database file and it should also be adding the player to it with some default information like username and stuff.

solid wolf
#

Like code wise

#

Because right now it seems like SettingsData is null

dark patrol
#

SettingsData would be the Class that holds the values and holds the getters and setters

solid wolf
#

getSettingsBuildMode returns null

dark patrol
#

Another thing im thinking about is that it throws and exception

#

Bc in my code i have it like this

#

Try {
<main return>
} catch(SQLExceptions e) {
<print error>
<return null>
}

#

i wrote that while on phone so might not be 100% acurate

solid wolf
#

There's your issue

dark patrol
#

But thats the structure

solid wolf
#

How are you getting the data from the file

dark patrol
#

In settingsData class i have the veriables and there is a function called "getBuildMode" that returns "this.buildMode"

#

If thats what you mean

#

It is using ORMLite

solid wolf
#

Yes can I see the code

dark patrol
#

Wait ill turn it on in a bit to show you

#

ill send it whenni can

#

Dms would be best

solid wolf
#

You can send it here

dark patrol
# solid wolf You can send it here
   public SettingsData getSettingsBuildMode(Player player) {
        try {
            return settingsDataDao.queryForId(player.getUniqueId().toString());
        } catch(SQLException exception) {
            System.out.println("Error:" + exception);
            return null;
        }
    }```
tawdry cryptBOT
dark patrol
#

This would be that one that returns null

solid wolf
#

What's in queryForId

dark patrol
#
public class SettingsDataService {

    private final Dao<SettingsData, String> settingsDataDao;

    public SettingsDataService(String path) throws SQLException {
        ConnectionSource connectionSource = new JdbcConnectionSource("jdbc:sqlite:" + path);
        TableUtils.createTableIfNotExists(connectionSource, SettingsData.class);
        settingsDataDao = DaoManager.createDao(connectionSource, SettingsData.class);
    }

    public SettingsData addPlayer(Player player) {
        try {
            SettingsData settingsData = new SettingsData();
            settingsData.setUuid(player.getUniqueId().toString());
            settingsData.setBuildMode(false);
            settingsDataDao.create(settingsData);
            return settingsData;
        } catch(SQLException exception) {
            System.out.println("Error:" + exception);
            return null;
        }
    }

    public void setSettingsBuildMode(Player player, Boolean mode){
        try {
            settingsDataDao.queryForId(player.getUniqueId().toString()).setBuildMode(mode);
        } catch(SQLException exception) {
            System.out.println("Error:" + exception);
        }
    }

    public SettingsData getSettingsBuildMode(Player player) {
        try {
            return settingsDataDao.queryForId(player.getUniqueId().toString());
        } catch(SQLException exception) {
            System.out.println("Error:" + exception);
            return null;
        }
    }
}```

Whole class for the SettingsData
tawdry cryptBOT
dark patrol
#

Its eather throwing an exception or there is nothing in the .db file

#
@DatabaseTable(tableName = "settings_data")
public class SettingsData {

    @DatabaseField(id = true)
    private String uuid;
    @DatabaseField(canBeNull = false)
    private boolean buildMode;

    public SettingsData() {}


    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public boolean getBuildMode() {
        return buildMode;
    }

    public void setBuildMode(boolean mode) {
        this.buildMode = mode;
    }
}```

SettingsData
tawdry cryptBOT
dark patrol
#

And if it does throw an exception, what am i supposed to return or how would i even stop it

#

Or it isnt even adding the player to the database in the first place

dark patrol
#

is there a way i can test and aee what part is not working?