· 10 years ago · Aug 24, 2016, 01:16 PM
1public class ByteSaveTest {
2 private static final String TABLE = "test_table";
3 //The statement used to build the table I'm testing on
4 private static final String BUILD_TABLE_STATEMENT =
5 "CREATE TABLE IF NOT EXISTS " + TABLE + " (id varchar(32) NOT NULL UNIQUE, test BLOB NOT NULL, PRIMARY KEY (id));";
6
7 //The test method
8 void runTest(String id) {
9 Bukkit.getLogger().info("Insert Result: " + saveByte(id, new byte[30]));
10 }
11
12 boolean saveByte(String rowID, byte[] byteTest) {
13 Connection connection = null;
14 PreparedStatement statement = null;
15 boolean result = false;
16 try {
17 connection = getConnection();//this method is elsewhere, and is confirmed to work
18 statement = connection.prepareStatement("INSERT INTO " + TABLE + " (id, test) VALUES(?, ?);");
19 statement.setString(1, rowID);
20 statement.setBytes(2, byteTest);
21 result = (statement.executeUpdate() != 0);
22 } catch (Exception e) {
23 Bukkit.getLogger().warning(SQLiteDatabase.sqlError);
24 ErrorLogger.log(e);
25 } finally {
26 try {
27 if (connection != null) connection.close();
28 if (statement != null) statement.close();
29 } catch (SQLException e) {
30 Bukkit.getLogger().warning(SQLiteDatabase.sqlError);
31 ErrorLogger.log(e);
32 }
33 }
34 return result;
35 }
36}