You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafodion.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/04/04 02:28:00 UTC

[jira] [Commented] (TRAFODION-3019) Use preparedStatement.setBytes to set a string to char() is wrong

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

ASF GitHub Bot commented on TRAFODION-3019:
-------------------------------------------

GitHub user mashengchen opened a pull request:

    https://github.com/apache/trafodion/pull/1505

    TRAFODION-3019 pstmt.setByte cannot support string.getbyte well

    fill in blank when give value to a char() type.
    support Chinese value, when column type is UCS2

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mashengchen/trafodion JIRA3019

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/trafodion/pull/1505.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1505
    
----
commit 7914d91ec16e631adacf5d866675bb6f7326e7fa
Author: aven <sh...@...>
Date:   2018-04-04T02:22:22Z

    TRAFODION-3019 pstmt.setByte cannot support string.getbyte well

----


> Use preparedStatement.setBytes to set a string to char() is wrong 
> ------------------------------------------------------------------
>
>                 Key: TRAFODION-3019
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3019
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: client-jdbc-t2, client-jdbc-t4
>            Reporter: mashengchen
>            Assignee: mashengchen
>            Priority: Major
>
> preparedStatement.setBytes(testsetBytes.getBytes()) set string to char(30) column expected: [testsetBytes] but was: [testsetBytesCharMinTable0]
> when set a blank string, expected:[] but was:[0p��CharMinTable0]
>  
> export LD_PRELOAD=$JAVA_HOME/jre/lib/amd64/libjsig.so:$TRAF_HOME/export/lib${SQ_MBTYPE}/libseabasesig.so
> javac T2_xxx3.java 
> java org.junit.runner.JUnitCore T2_xxx3
> java file
> import static org.junit.Assert.*;
> import java.sql.*;
> import org.junit.Test;
> public class T2_xxx3
> {
>         @Test
>     public void main()throws Exception
>     {
>         Connection conn;
>         Statement stmt;
>         PreparedStatement pstmt;
>         ResultSet rs;
>         try
>         {
>             Class.forName("org.apache.trafodion.jdbc.t2.T2Driver");
>             System.out.println("Class loaded");
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>             fail(e.getMessage());
>             System.out.println(e.getMessage());
>             return;
>         }
>         try
>         {
>                 String testCharMinTableName = "testCharMinTable";
>                 String testData = "testsetBytes";
>                 byte[] testBytes = null;
>                 testBytes = testData.getBytes();
>                 String dml = "upsert using load into "+testCharMinTableName+" values(?,?)";
>             String url = "jdbc:t2jdbc:";
>             System.out.println("Opening connection...");
>             conn = DriverManager.getConnection(url);
>             System.out.println("Successfully connected");
>             stmt = conn.createStatement();
>             stmt.execute("create table IF NOT EXISTS " + testCharMinTableName
>                                         + " (c_id int not null,c_char char(30), primary key(c_id) )");
>             System.out.println("create table if not exists!");
>             stmt.execute("delete from " + testCharMinTableName);
>             System.out.println("clean table data ");
>             pstmt = conn.prepareStatement(dml);
>             pstmt.setInt(1, 1);
>             pstmt.setBytes(2, testBytes);
>             pstmt.execute();
>             System.out.println("insert success");
>             stmt = conn.createStatement();
>             rs = stmt.executeQuery("select * from " + testCharMinTableName);
>             rs.next();
>             System.out.println("by getString to select char value is: " + rs.getString(2));
>             System.out.println("by getBytes to select char value is: " + new String(rs.getBytes(2)).trim());
>             assertEquals(testData, new String(rs.getBytes(2)).trim());
>         }
>        catch (Exception e)
>         {
>             e.printStackTrace();
>             System.out.println(e.getMessage());
>             fail(e.getMessage());
>             return;
>         }finally{
>         }
>     }
> }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)