获取"无效的列类型"同时将java对象序列化为oracle数据库

时间:2016-02-22 06:52:46

标签: java oracle serialization

我创建了一个数据类型为CLOB的列,并在尝试将JAVA对象序列化到该列时获得以下异常

INFO: using Agent sizeof engine
java.sql.SQLException: Invalid column type
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8516)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8034)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8767)
    at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8748)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:230)
    at com.oneshield.service.policyworkflow.ExecuteAsyncTest.writeJavaObject(ExecuteAsyncTest.java:108)
    at com.oneshield.service.policyworkflow.ExecuteAsyncTest.testSerializeDesirialize(ExecuteAsyncTest.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

该计划

public static long writeJavaObject(Connection conn, Object object)  {
        PreparedStatement pstmt;
        try
        {
            pstmt = conn.prepareStatement(writeSQL);
            pstmt.setObject(1, object);
             pstmt.setLong(2, 23205557351L);

                pstmt.executeUpdate();
                return 23205557351L;
        }
        catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return 0L;
      }


public void testSerializeDesirialize() throws Exception
    {
        String sql = "update sl_service_op_log set request_object = ? where job_id = ?";
        Connection connection = dataAccessManager.getConnection();

创建java对象

ServiceLayerOperationRequest serviceLayerOperationRequest = new ServiceLayerOperationRequest();
        serviceLayerOperationRequest.setSe`enter code here`ssionId("23133356761");
        serviceLayerOperationRequest.setServiceOpInvocationId("Oneshield");
        serviceLayerOperationRequest.setTransactionId("1");

        writeJavaObject(connection, serviceLayerOperationRequest);      
    }

0 个答案:

没有答案