Uploaded image for project: 'Apache Trafodion (Retired)'
  1. Apache Trafodion (Retired)
  2. TRAFODION-3019

Use preparedStatement.setBytes to set a string to char() is wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      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

      {         }

          }
      }

      Attachments

        Issue Links

          Activity

            People

              shengchen.ma mashengchen
              shengchen.ma mashengchen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: