Java 从MySql数据库加载UUID
我有一个数据库,我使用UUID作为主键。我使用java将UUID存储为二进制文件(16)。要保存条目,我使用以下命令Java 从MySql数据库加载UUID,java,mysql,uuid,Java,Mysql,Uuid,我有一个数据库,我使用UUID作为主键。我使用java将UUID存储为二进制文件(16)。要保存条目,我使用以下命令 public boolean saveEntry(UUID id , String, name, int p1, int p2) throws SQLException { byte[] uuidBytes = new byte[16]; ByteBuffer.wrap(uuidBytes).order(ByteOrder.BIG_ENDIAN).putLong(
public boolean saveEntry(UUID id , String, name, int p1, int p2) throws SQLException
{
byte[] uuidBytes = new byte[16];
ByteBuffer.wrap(uuidBytes).order(ByteOrder.BIG_ENDIAN).putLong(id.getMostSignificantBits())
.putLong(id.getLeastSignificantBits());
String updateQuery = "INSERT INTO " + databaseTableName + " (ID, Name, p1, p2) "
+ "VALUES " + "(?, ?, ?, ?) "
PreparedStatement statement = null;
// write the id in the workflow table
statement = databaseConnection.prepareStatement(updateQuery);
statement.setBytes(1, uuidBytes);
statement.setString(2, name);
statement.setInt(3, p1);
statement.setInt(4, p2);
statement.execute();
这部分正在工作,我可以在数据库中看到我的条目
但是,当我尝试加载带有以下内容的条目时:
public Workflow loadEntry(UUID id) throws SQLException
{
byte[] uuidBytes = new byte[16];
ByteBuffer.wrap(uuidBytes).order(ByteOrder.BIG_ENDIAN).putLong(id.getMostSignificantBits())
.putLong(id.getLeastSignificantBits());
String query = "SELECT " + "* " + "FROM " + databaseTableName + " WHERE " + databaseTableName
+ ".ID = ?";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
{
preparedStatement = databaseConnection.prepareStatement(query);
preparedStatement.setBytes(1, uuidBytes);
resultSet = preparedStatement.executeQuery(query);
我犯了以下错误:
您的SQL语法有错误;检查手册
对应于您的MySQL服务器版本,以便使用正确的语法
在第1行的“?”附近
我不太清楚错误的原因是什么。我知道使用
id.toString()。那么有什么办法可以绕过这个解决方案吗?实际表中ID
列的类型是什么?binary(16)@TimBiegeleisen实际表中ID
列的类型是什么?binary(16)@TimBiegeleisen