[ 
https://issues.apache.org/jira/browse/DERBY-1997?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13923847#comment-13923847
 ] 

Knut Anders Hatlen commented on DERBY-1997:
-------------------------------------------

Hi Kim,

What code are you running when you see the differing exceptions? When I run the 
WwdEmbedded and WwdClientExample classes in the java/demo directory using head 
of trunk, I see these exceptions:

{noformat}
% java WwdEmbedded
Connected to database jdbcDemoDB
Enter wish-list item (enter exit to end): 
I wish to see a Java program fail
 . . . exception thrown:
java.sql.SQLDataException: A truncation error was encountered trying to shrink 
VARCHAR 'I wish to see a Java program fail' to length 32.
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:83)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:233)
        at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:424)
        at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:353)
        at 
org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2396)
        at 
org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:82)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1430)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1709)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeLargeUpdate(EmbedPreparedStatement.java:320)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:309)
        at WwdEmbedded.main(WwdEmbedded.java:85)
Caused by: ERROR 22001: A truncation error was encountered trying to shrink 
VARCHAR 'I wish to see a Java program fail' to length 32.
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:290)
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:285)
        at 
org.apache.derby.iapi.types.SQLChar.hasNonBlankChars(SQLChar.java:1846)
        at org.apache.derby.iapi.types.SQLVarchar.normalize(SQLVarchar.java:181)
        at org.apache.derby.iapi.types.SQLVarchar.normalize(SQLVarchar.java:158)
        at 
org.apache.derby.iapi.types.DataTypeDescriptor.normalize(DataTypeDescriptor.java:647)
        at 
org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeColumn(NormalizeResultSet.java:332)
        at 
org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeRow(NormalizeResultSet.java:376)
        at 
org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(NormalizeResultSet.java:191)
        at 
org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(DMLWriteResultSet.java:142)
        at 
org.apache.derby.impl.sql.execute.InsertResultSet.getNextRowCore(InsertResultSet.java:1175)
        at 
org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:453)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:470)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:349)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1338)
        ... 4 more
Getting Started With Derby JDBC program ending.

% java WwdClientExample
Connected to database jdbcDemoDB
 . . . . creating table WISH_LIST
Enter wish-list item (enter exit to end): 
I wish to see a Java program fail
 . . . exception thrown:

---SQLException Caught---

SQLState:   22001
Severity: 30000
Message:  A truncation error was encountered trying to shrink VARCHAR 'I wish 
to see a Java program fail' to length 32.
java.sql.SQLDataException: A truncation error was encountered trying to shrink 
VARCHAR 'I wish to see a Java program fail' to length 32.
        at 
org.apache.derby.client.am.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:72)
        at 
org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:321)
        at 
org.apache.derby.client.am.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:404)
        at WwdClientExample.main(WwdClientExample.java:81)
Caused by: ERROR 22001: A truncation error was encountered trying to shrink 
VARCHAR 'I wish to see a Java program fail' to length 32.
        at 
org.apache.derby.client.am.ClientStatement.completeExecute(ClientStatement.java:1861)
        at 
org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(NetStatementReply.java:323)
        at 
org.apache.derby.client.net.NetStatementReply.readExecute(NetStatementReply.java:72)
        at 
org.apache.derby.client.net.StatementReply.readExecute(StatementReply.java:59)
        at 
org.apache.derby.client.net.NetPreparedStatement.readExecute_(NetPreparedStatement.java:167)
        at 
org.apache.derby.client.am.ClientPreparedStatement.readExecute(ClientPreparedStatement.java:1842)
        at 
org.apache.derby.client.am.ClientPreparedStatement.flowExecute(ClientPreparedStatement.java:2129)
        at 
org.apache.derby.client.am.ClientPreparedStatement.executeUpdateX(ClientPreparedStatement.java:409)
        at 
org.apache.derby.client.am.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:395)
        ... 1 more
Getting Started With Derby JDBC program ending.
{noformat}

Both chains have two exceptions.

> Misleading text in WwdEmbedded demo source file for Working With Derby
> ----------------------------------------------------------------------
>
>                 Key: DERBY-1997
>                 URL: https://issues.apache.org/jira/browse/DERBY-1997
>             Project: Derby
>          Issue Type: Bug
>          Components: Demos/Scripts, Documentation
>    Affects Versions: 10.2.1.6
>            Reporter: Kim Haase
>            Assignee: Kim Haase
>            Priority: Minor
>              Labels: derby_triage10_5_2
>         Attachments: vcs-diff3523819486798216332.patch, 
> vcs-diff7276709987551559550.patch
>
>
> I'm making some minor fixes to the Working With Derby manual (DERBY-1948, 
> DERBY-1972). The description of the WwdEmbedded.java program in the HTML 
> generated from the file rwwdactivity3.dita 
> (http://db.apache.org/derby/docs/dev/workingwithderby/) contains the 
> following paragraph:
> DERBY EXCEPTION REPORTING CLASSES: The two methods at the end of the file, 
> errorPrint and SQLExceptionPrint, are generic exception reporting routines 
> that can be used with any JDBC program. This type of exception handling is 
> required because often multiple exceptions (SQLException) are chained 
> together then thrown. A while loop is used to report on each error in the 
> chain. These classes are used by calling the errorPrint method from the catch 
> block of the code that accesses the database.
> The introductory text "DERBY EXCEPTION REPORTING CLASSES" is keyed to a 
> comment with the same text in the 
> DERBY_HOME/demo/programs/workingwithderby/WwdEmbedded.java program:
>      //   ## DERBY EXCEPTION REPORTING CLASSES  ## 
>     /***     Exception reporting methods
>     **      with special handling of SQLExceptions
>     ***/
> The problem is that there are no Derby exception reporting classes, only 
> methods, as far as I can tell. The use of the term CLASSES is likely to 
> confuse any users not well acquainted with Java (one of the target audiences 
> of this manual). It would be great if someone could change CLASSES to METHODS 
> in the WwdEmbedded.java file so that I can make the corresponding fix to the 
> rwwdactivity3.dita file. I would also have to correct the confusing last 
> sentence of the paragraph; I think it would make more sense to say, "The 
> program starts this process by calling the errorPrint method from the catch 
> block of the code that accesses the database." (I can't just change "classes" 
> to "methods" because errorPrint *is* one of the methods.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to