从MySql数据库加载UUID

时间:2017-02-11 10:43:36

标签: java mysql uuid

我有一个数据库,我使用UUID作为主键。我使用java将uuids存储为二进制文件(16)。要保存条目,请使用以下

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.ibm.mq.headers.internal.HeaderType
        at com.ibm.mq.headers.pcf.PCFMessage.<init>(PCFMessage.java:77) ~[com.ibm.mq.headers-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.headers.pcf.PCFMessage.<init>(PCFMessage.java:132) ~[com.ibm.mq.headers-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.service.PolicyServiceImpl.policyFromPcf(PolicyServiceImpl.java:575) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.intercept.JmqiOpenInterceptorImpl.storeSecurityInfoInSmqiObject(JmqiOpenInterceptorImpl.java:359) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.intercept.JmqiOpenInterceptorImpl.readPolicyIfAvailable(JmqiOpenInterceptorImpl.java:321) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.intercept.JmqiOpenInterceptorImpl.afterSpiOpen(JmqiOpenInterceptorImpl.java:203) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.spiOpen(InterceptedJmqiImpl.java:411) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.ese.jmqi.ESEJMQI.spiOpen(ESEJMQI.java:513) ~[com.ibm.mq.jmqi-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.msg.client.wmq.internal.WMQMessageProducer$SpiIdentifiedProducerShadow.initialise(WMQMessageProducer.java:762) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.msg.client.wmq.internal.WMQMessageProducer.<init>(WMQMessageProducer.java:995) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.msg.client.wmq.internal.WMQSession.createProducer(WMQSession.java:889) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.msg.client.jms.internal.JmsSessionImpl.createProducer(JmsSessionImpl.java:1232) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.msg.client.jms.internal.JmsQueueSessionImpl.createSender(JmsQueueSessionImpl.java:136) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.jms.MQQueueSession.createSender(MQQueueSession.java:153) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at com.ibm.mq.jms.MQQueueSession.createProducer(MQQueueSession.java:254) ~[com.ibm.mqjms-7.5.0.6.jar:7.5.0.6 - p750-006-160226]
        at org.springframework.jms.core.JmsTemplate.doCreateProducer(JmsTemplate.java:1114) ~[spring-jms-4.3.4.RELEASE.jar:4.3.4.RELEASE]
        at org.springframework.jms.core.JmsTemplate.createProducer(JmsTemplate.java:1095) ~[spring-jms-4.3.4.RELEASE.jar:4.3.4.RELEASE]
        at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:482) ~[camel-jms-2.17.0.jar:2.17.0]
        at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:428) ~[camel-jms-2.17.0.jar:2.17.0]
        at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$1.doInJms(JmsConfiguration.java:442) ~[camel-jms-2.17.0.jar:2.17.0]
        at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:484) ~[spring-jms-4.3.4.RELEASE.jar:4.3.4.RELEASE]

这部分正常,我可以在数据库中查看我的条目。

但是一旦我尝试加载条目:

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();

我得到以下错误:

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近&#39;?&#39;在第1行

我不太确定错误的原因是什么。我知道使用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); 有效,但我不确定这种方式的性能和功能。那么有什么方法可以解决这个问题吗?

0 个答案:

没有答案