[
https://issues.apache.org/jira/browse/TRAFODION-3019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16430646#comment-16430646
]
ASF GitHub Bot commented on TRAFODION-3019:
-------------------------------------------
Github user asfgit closed the pull request at:
https://github.com/apache/trafodion/pull/1505
> 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)