Last active
August 24, 2016 10:13
-
-
Save Fupery/822296dc3731836cd6626965fbaf09e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ByteSaveTest { | |
private static final String TABLE = "test_table"; | |
//The statement used to build the table I'm testing on | |
private static final String BUILD_TABLE_STATEMENT = | |
"CREATE TABLE IF NOT EXISTS " + TABLE + " (id varchar(32) NOT NULL UNIQUE, test BLOB NOT NULL, PRIMARY KEY (id));"; | |
//The test method | |
void runTest(String id) { | |
Bukkit.getLogger().info("Insert Result: " + saveByte(id, new byte[30])); | |
} | |
boolean saveByte(String rowID, byte[] byteTest) { | |
Connection connection = null; | |
PreparedStatement statement = null; | |
boolean result = false; | |
try { | |
connection = getConnection();//this method is elsewhere, and is confirmed to work | |
statement = connection.prepareStatement("INSERT INTO " + TABLE + " (id, test) VALUES(?, ?);"); | |
statement.setString(1, rowID); | |
statement.setBytes(2, byteTest); | |
result = (statement.executeUpdate() != 0); | |
} catch (Exception e) { | |
Bukkit.getLogger().warning(SQLiteDatabase.sqlError); | |
ErrorLogger.log(e); | |
} finally { | |
try { | |
if (connection != null) connection.close(); | |
if (statement != null) statement.close(); | |
} catch (SQLException e) { | |
Bukkit.getLogger().warning(SQLiteDatabase.sqlError); | |
ErrorLogger.log(e); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment