Help with Java SQLite 3 in Replit

Question:

I’m having problems getting my database to function properly. When loading a new save, the program works fine. However, when I try to save data, the program returns an error saying that there’s no suitable driver found. Also, the program doesn’t seem to create a new .db file on first run, which is what I want it to do. Please help!
(For reference, all of my Java SQL code is in UserDatabase/UserDatabase.java)


Repl link:
@drybowser48/Spirit-Fight-Arena-Legends-WIP

code snippet

Question:
Hi, it’s me again.

This is an update from my previous forum post (Help with Java SQLite 3 in Replit), where I couldn’t get my Java SQL database to function at all.

Now, I figured out how to read and write data to my .db file, and it works…except with Arrays. For some reason, it keeps saying my Array table doesn’t exist when I clearly define it like the other tables. Can someone help me fix this issue?

(All SQL operations are in UserDatabase.java)
Repl link:
https://replit.com/@drybowser48/Spirit-Fight-Arena-Legends-WIP#UserDatabase.java

code snippet

Can you show the error/trace back?

I get something like this:

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: PROGARRAYS)
    at org.sqlite.core.DB.newSQLException(DB.java:1179)
    at org.sqlite.core.DB.newSQLException(DB.java:1190)
    at org.sqlite.core.DB.throwex(DB.java:1150)
    at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
    at org.sqlite.core.NativeDB.prepare(NativeDB.java:126)
    at org.sqlite.core.DB.prepare(DB.java:264)
    at org.sqlite.jdbc3.JDBC3Statement.lambda$executeQuery$1(JDBC3Statement.java:81)
    at org.sqlite.jdbc3.JDBC3Statement.withConnectionTimeout(JDBC3Statement.java:454)
    at org.sqlite.jdbc3.JDBC3Statement.executeQuery(JDBC3Statement.java:79)
    at UserDatabase.getProgArrays(UserDatabase.java:203)
    at Hub.loadFile(Hub.java:116)
    at Main.main(Main.java:66)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:459)
    at Hub.loadFile(Hub.java:117)
    at Main.main(Main.java:66)

Note: This occurs when there is an established Save File and I try to load it in.

It seems your table has not been created yet, did you forget to run the init?

The table is created in UserDatabase.initTables(), and the initializers for the data should be in Hub.initFile(), which is run when you access Hub.visit() for the first time. The weird thing is that every table is initialized except for Progarrays, and I can’t figure out why.

In Hub.initFile() You never call UserDatabase.initTables()

Alright, so I did that, and the database now recognizes the Progarrays table. However, I’m now having difficulties retrieving the array from the table.

The Program is supposed to get the arrays from Progarrays and store them into an ArrayList. However, the ArrayList returned from getProgArrays() is empty, even though I have add statements that are supposed to fill the array.

I see you have a try/except block, is that catching anything?

Nothing except a printStackTrace() statement, why?

Does that print print anything? Because it could error before it even adds anything. ( then it would be caught and printed)

Edit: I just realized that you are getting int col’s that don’t exist, so it would error.

I did notice that. I can’t figure out why the columns don’t exist when I initialize and add data to Progarrays like the other tables. Does it have to do with how I’m adding and/or getting the arrays?

(Note: Sorry for the sudden silence; I had to do some school stuff, and thanks for the help.)

Yeah, I think you are having issues with that. If it is not sensitive, could you run sqlite3 <db name> .dump and paste the data here?

1 Like

I don’t know if I did it right, but I got something like

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
COMMIT;

Nevermind, I got it now.

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE PLAYER (id integer NOT NULL, FIGHTER BLOB, PRIMARY KEY (id));
INSERT INTO PLAYER VALUES(1,X'aced00057372000746696768746572b135f6dc22ea939e02002c440004614d6f6444000561726d485044000361746b490007636f756e74657244000863757241726d485044000563757248504400056375724d504400106375727365644d756c7469706c696572440004644d6f64440003646566440003657870440004684d6f6444000368697444000268705a000e69735479706553706563696669634900056c6576656c4400046c75636b4400056d414d6f644400046d41746b4400056d444d6f644400046d4465664400056d657465724400156d657465724368617267654d756c7469706c6965724400026d7044000e726167654d756c7469706c696572440004734d6f64440010736869656c644d756c7469706c69657244000373706444001273796d62696f74654d756c7469706c6965724c00076162696c6974797400124c6a6176612f6c616e672f537472696e673b4c000667656e64657271007e00015b00066865616c74687400025b5a5b00096865616c74685265667400135b4c6a6176612f6c616e672f537472696e673b5b00076d6f76655573657400025b494c00046e616d6571007e00014c00096f70656e536c6f74737400154c6a6176612f7574696c2f41727261794c6973743b4c0005736c6f743171007e00014c0005736c6f743271007e00014c0005736c6f743371007e00014c0005736c6f743471007e00014c000a7370697269744d6f766571007e00014c00067374616e636571007e00014c000673746174757371007e00014c00047479706571007e000178703ff000000000000000000000000000004044000000000000000000000000000000000000405900000000000040240000000000003ff00000000000003ff0000000000000404180000000000000000000000000003ff00000000000004059000000000000405b000000000000000000000140180000000000003ff000000000000040428000000000003ff0000000000000404180000000000000000000000000003ff000000000000040240000000000003ff00000000000003ff00000000000003ff0000000000000403f0000000000003ff00000000000007400007400044d616c65757200025b5a578f203914b85de202000078700000000700000000000000757200135b4c6a6176612e6c616e672e537472696e673badd256e7e91d7b470200007870000000077400044275726e740008506f69736f6e6564740009506172616c797a656474000646726f7a656e740007456e7261676564740008436f6e66757365647400074865616c746879757200025b494dba602676eab2a5020000787000000004000000000000000000000000000000007400034a6f6e737200136a6176612e7574696c2e41727261794c6973747881d21d99c7619d03000149000473697a65787000000002770400000002740005536c61736874000850726573737572657871007e001971007e001a71007e000771007e000771007e00077400064e6f726d616c71007e001b74000746696768746572');
CREATE TABLE PROGINTS (id integer NOT NULL, TIMESVISITED INTEGER NOT NULL, STORYPROG INTEGER NOT NULL, GOLD INTEGER NOT NULL, TOTALBATTLES INTEGER NOT NULL, TOTALG INTEGER NOT NULL, TOTALWINS INTEGER NOT NULL, TOTALLOSSES INTEGER NOT NULL, TALKSTATE1 INTEGER NOT NULL, TALKSTATE2 INTEGER NOT NULL, TALKSTATE3 INTEGER NOT NULL, TALKSTATE4 INTEGER NOT NULL, TEXTSPEED INTEGER NOT NULL, PRIMARY KEY (id));
INSERT INTO PROGINTS VALUES(1,1,0,0,0,0,0,0,0,0,0,0,70);
CREATE TABLE PROGARRAYS (id integer, ITEMS ARRAY NOT NULL, TRADES ARRAY NOT NULL, SIDEQUESTSTATES ARRAY NOT NULL, TALKSTATES ARRAY NOT NULL, PRIMARY KEY (id));
CREATE TABLE PROGBOOLEANS (id integer, FOUGHTCAV INTEGER NOT NULL, KNOWSKAI INTEGER NOT NULL, KAIKNOWSNAME INTEGER NOT NULL, BARRACKSECRET INTEGER NOT NULL, ANGERSTATE INTEGER NOT NULL, ACCESSLIGHT INTEGER NOT NULL, HASLIGHTKEY1 INTEGER NOT NULL, HASLIGHTKEY2 INTEGER NOT NULL, HASLIGHTKEY3 INTEGER NOT NULL, HASARCHIVEKEY INTEGER NOT NULL, HASSTORAGEKEY INTEGER NOT NULL, HASSECRETDOC INTEGER NOT NULL, HASSECRETNOTE INTEGER NOT NULL, MOVEINFO INTEGER NOT NULL, SHOWDEBUG INTEGER NOT NULL, PRIMARY KEY (id));
INSERT INTO PROGBOOLEANS VALUES(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
COMMIT;