Zsolt Koppany wrote:
Hi,

with all newer derby versions I get an Exception if I want to store NULL
values.

The exception was added as part of DERBY-1610, see release note
https://issues.apache.org/jira/secure/attachment/12361353/releaseNote.html, but
none of the cases called out in the release note cover your problem.
The question here is why you are getting a data value type of <UNKNOWN>.
We need to try to get a JDBC program to reproduce your problem so we can look at it. We need the schema of the table and the prepareStatement and setNull code to reproduce. Can you provide this? Perhaps you can modify the program below to show the error.

Thanks

Kathey

import java.sql.*;
import org.apache.derby.drda.NetworkServerControl;
import java.io.*;

public class Test22005Exception {

   public static void main(String[] args) throws Exception {
   NetworkServerControl nsctrl = new NetworkServerControl();
   nsctrl.start(new PrintWriter(System.out));
       pingUntilUp();
   Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/wombat;create=true");
   Statement s = conn.createStatement();
   try {
       s.executeUpdate("DROP TABLE TAB");
   }catch (SQLException se) {};
   s.executeUpdate("CREATE TABLE TAB (vc varchar(20))");
PreparedStatement ps = conn.prepareStatement("INSERT INTO TAB VALUES(?)");
   ps.setNull(1,java.sql.Types.VARCHAR);
   ps.executeUpdate();
   System.out.println("Insert successful");
   nsctrl.shutdown();
}

   private static void pingUntilUp() throws Exception{
   NetworkServerControl nsctrl = new NetworkServerControl();
   int i;
   for (i = 1; i < 30; i++) {
       try {
       nsctrl.ping();
       } catch (Exception e) {
       if (i == 30)
           throw e;
       else
           Thread.sleep(1000);
       }
   }
   }
}

Derby (or ibatis) wants my application telling also the java type of the
NULL value something like below:

#value:INTEGER#

Our application runs with Mysql-4 and 5, Oracle and Postgress. We cannot modify all ibatis files and additional we should write a lot
of new tests testing all possible NULL values.

We use ibatis-2.3.4.726 and derby 10.4.2.0.

How can we fix the problem?
2
Zsolt

com.intland.codebeamer.persistence.util.PersistenceException:
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the createUser-InlineParameterMap.
--- Check the parameter mapping for the 'hostName' property.
--- Cause: java.sql.SQLException: An attempt was made to get a data
value of type '<UNKNOWN>' from a data value of type 'VARCHAR'.
    at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
    at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
    at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
    at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert(SqlMapClientImpl.java:58)
    at
com.intland.codebeamer.persistence.util.SqlMapClientWrapper.insert(SqlMapClientWrapper.java:302)
    at
com.intland.codebeamer.persistence.dao.AbstractDao.create(AbstractDao.java:82)
    at
com.intland.codebeamer.persistence.dao.impl.UserDaoImpl.create(UserDaoImpl.java:90)
    at
com.intland.codebeamer.persistence.test.AbstractUserPersistenceTests.createAccount(AbstractUserPersistenceTests.java:42)
    at
com.intland.codebeamer.persistence.test.AbstractProjectPersistenceTests.setUpBeforeClass(AbstractProjectPersistenceTests.java:102)
    at
com.intland.codebeamer.test.AbstractCodeBeamerTests.onSetUp(AbstractCodeBeamerTests.java:132)
    at
com.intland.codebeamer.persistence.test.AbstractPersistenceTests.onSetUp(AbstractPersistenceTests.java:467)
    at
org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:103)
    at junit.framework.TestCase.runBare(TestCase.java:125)
    at
org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the createUser-InlineParameterMap.
--- Check the parameter mapping for the 'hostName' property.
--- Cause: java.sql.SQLException: An attempt was made to get a data
value of type '<UNKNOWN>' from a data value of type 'VARCHAR'.
    ... 26 more
Caused by: java.sql.SQLException: An attempt was made to get a data
value of type '<UNKNOWN>' from a data value of type 'VARCHAR'.
    at
org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown
Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.client.am.PreparedStatement.setNull(Unknown Source)
    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:585)
    at
com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:70)
    at $Proxy1.setNull(Unknown Source)
    at
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:172)
    at
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
    at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
    at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
    at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
    ... 25 more
Caused by: org.apache.derby.client.am.SqlException: An attempt was made
to get a data value of type '<UNKNOWN>' from a data value of type 'VARCHAR'.
    at
org.apache.derby.client.am.PreparedStatement$PossibleTypes.throw22005Exception(Unknown
Source)
    ... 37 more






Reply via email to