You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafodion.apache.org by "mashengchen (JIRA)" <ji...@apache.org> on 2018/04/04 02:12:00 UTC
[jira] [Updated] (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:all-tabpanel ]
mashengchen updated TRAFODION-3019:
-----------------------------------
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{
}
}
}
was:
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]
> 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)